The TEMPLATE structure has been completely changed.
This commit is contained in:
@@ -1,26 +1,24 @@
|
|||||||
# Django Template
|
# Django Template
|
||||||
|
|
||||||
This repository contains a reusable Django project template in
|
This repository contains a reusable Django project template at the repository
|
||||||
`django_template/`. The existing sample project remains available at the
|
root.
|
||||||
repository root and is not used as the template source.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
From the directory that contains this repository, create a new project with:
|
From the directory that contains this repository, create a new project with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
django-admin startproject myproject --template=djangotemplate/django_template
|
django-admin startproject myproject --template=djangotemplate
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
django-admin startproject myproject \
|
django-admin startproject myproject --template=https://gitea.ta1sph.info/suphicakir/django-template-v2/archive/main.zip
|
||||||
--template=https://gitea.ta1sph.info/suphicakir/django-template-v2/archive/main.zip
|
|
||||||
```
|
```
|
||||||
For this repository's virtual environment, use:
|
For this repository's virtual environment, use:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
djangotemplate/env/bin/django-admin startproject myproject \
|
djangotemplate/env/bin/django-admin startproject myproject \
|
||||||
--template=djangotemplate/django_template
|
--template=djangotemplate
|
||||||
```
|
```
|
||||||
|
|
||||||
Then initialize and run the generated project:
|
Then initialize and run the generated project:
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
# Django Project Template
|
|
||||||
|
|
||||||
This directory is a reusable template for `django-admin startproject`.
|
|
||||||
|
|
||||||
## Create a project
|
|
||||||
|
|
||||||
From the directory that contains this repository, run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
django-admin startproject myproject --template=djangotemplate/django_template
|
|
||||||
```
|
|
||||||
|
|
||||||
Then start the development server:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd myproject
|
|
||||||
python manage.py migrate
|
|
||||||
python manage.py runserver
|
|
||||||
```
|
|
||||||
|
|
||||||
## Included structure
|
|
||||||
|
|
||||||
- `project_name/`: Django project settings, URL configuration, ASGI, and WSGI modules. Django replaces this directory name with the name supplied to `startproject`.
|
|
||||||
- `apps/core/`: A starter application with an index route and template.
|
|
||||||
- `templates/`: Project-level base template.
|
|
||||||
- `static/`: Project-level CSS, JavaScript, fonts, and images directories.
|
|
||||||
- `media/`: Development media upload directory.
|
|
||||||
|
|
||||||
Add applications, environment-specific settings, static assets, and deployment configuration for each new project as needed.
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register models here.
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class CoreConfig(AppConfig):
|
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = 'apps.core'
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Define models here.
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{% extends 'Baselayout.html' %}
|
|
||||||
|
|
||||||
{% block title %}Home{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
Welcome to your Django project.
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Write tests here.
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
|
|
||||||
from . import views
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path('', views.IndexView.as_view(), name='index'),
|
|
||||||
]
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
from django.views.generic import TemplateView
|
|
||||||
|
|
||||||
|
|
||||||
class IndexView(TemplateView):
|
|
||||||
template_name = 'apps/core/index.html'
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
"""Django's command-line utility for administrative tasks."""
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Run administrative tasks."""
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
|
|
||||||
try:
|
|
||||||
from django.core.management import execute_from_command_line
|
|
||||||
except ImportError as exc:
|
|
||||||
raise ImportError(
|
|
||||||
"Couldn't import Django. Are you sure it's installed and "
|
|
||||||
"available on your PYTHONPATH environment variable? Did you "
|
|
||||||
"forget to activate a virtual environment?"
|
|
||||||
) from exc
|
|
||||||
execute_from_command_line(sys.argv)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
"""ASGI config for {{ project_name }} project."""
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
|
||||||
|
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
|
|
||||||
|
|
||||||
application = get_asgi_application()
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
"""Django settings for {{ project_name }} project."""
|
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
||||||
|
|
||||||
SECRET_KEY = 'django-insecure-change-me-in-production'
|
|
||||||
DEBUG = True
|
|
||||||
ALLOWED_HOSTS = []
|
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
|
||||||
'django.contrib.admin',
|
|
||||||
'django.contrib.auth',
|
|
||||||
'django.contrib.contenttypes',
|
|
||||||
'django.contrib.sessions',
|
|
||||||
'django.contrib.messages',
|
|
||||||
'django.contrib.staticfiles',
|
|
||||||
'apps.core',
|
|
||||||
]
|
|
||||||
|
|
||||||
MIDDLEWARE = [
|
|
||||||
'django.middleware.security.SecurityMiddleware',
|
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
||||||
'django.middleware.common.CommonMiddleware',
|
|
||||||
'django.middleware.csrf.CsrfViewMiddleware',
|
|
||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
||||||
]
|
|
||||||
|
|
||||||
ROOT_URLCONF = '{{ project_name }}.urls'
|
|
||||||
|
|
||||||
TEMPLATES = [
|
|
||||||
{
|
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
||||||
'DIRS': [BASE_DIR / 'templates'],
|
|
||||||
'APP_DIRS': True,
|
|
||||||
'OPTIONS': {
|
|
||||||
'context_processors': [
|
|
||||||
'django.template.context_processors.request',
|
|
||||||
'django.contrib.auth.context_processors.auth',
|
|
||||||
'django.contrib.messages.context_processors.messages',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
WSGI_APPLICATION = '{{ project_name }}.wsgi.application'
|
|
||||||
|
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
|
||||||
TIME_ZONE = 'UTC'
|
|
||||||
USE_I18N = True
|
|
||||||
USE_TZ = True
|
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
|
||||||
STATICFILES_DIRS = [BASE_DIR / 'static']
|
|
||||||
MEDIA_URL = 'media/'
|
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
"""URL configuration for {{ project_name }} project."""
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.conf.urls.static import static
|
|
||||||
from django.contrib import admin
|
|
||||||
from django.urls import include, path
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path('admin/', admin.site.urls),
|
|
||||||
path('', include('apps.core.urls')),
|
|
||||||
]
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
"""WSGI config for {{ project_name }} project."""
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
|
||||||
|
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
|
|
||||||
|
|
||||||
application = get_wsgi_application()
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
margin: 0 auto;
|
|
||||||
max-width: 960px;
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{% load static %}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
|
||||||
<title>{% block title %}Django Project{% endblock %}</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main class="container">
|
|
||||||
<h1>{% block content %}Django Project{% endblock %}</h1>
|
|
||||||
</main>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user