diff --git a/README.md b/README.md index e69de29..8229529 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,33 @@ +# Django Template + +This repository contains a reusable Django project template in +`django_template/`. The existing sample project remains available at the +repository root and is not used as the template source. + +## Usage + +From the directory that contains this repository, create a new project with: + +```bash +django-admin startproject myproject --template=djangotemplate/django_template +``` + +For this repository's virtual environment, use: + +```bash +djangotemplate/env/bin/django-admin startproject myproject \ + --template=djangotemplate/django_template +``` + +Then initialize and run the generated project: + +```bash +cd myproject +python manage.py migrate +python manage.py runserver +``` + +The generated project includes a `core` application, a home page, project-level +templates, static directories, and a media directory. Configure secrets, +allowed hosts, installed applications, assets, and deployment settings for the +new project before production use. diff --git a/django_template/README.md b/django_template/README.md new file mode 100644 index 0000000..af3135a --- /dev/null +++ b/django_template/README.md @@ -0,0 +1,29 @@ +# 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. \ No newline at end of file diff --git a/django_template/apps/core/admin.py b/django_template/apps/core/admin.py new file mode 100644 index 0000000..0ed20cd --- /dev/null +++ b/django_template/apps/core/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register models here. \ No newline at end of file diff --git a/django_template/apps/core/apps.py b/django_template/apps/core/apps.py new file mode 100644 index 0000000..bea492a --- /dev/null +++ b/django_template/apps/core/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apps.core' \ No newline at end of file diff --git a/django_template/apps/core/models.py b/django_template/apps/core/models.py new file mode 100644 index 0000000..2503b27 --- /dev/null +++ b/django_template/apps/core/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Define models here. \ No newline at end of file diff --git a/django_template/apps/core/templates/apps/core/index.html b/django_template/apps/core/templates/apps/core/index.html new file mode 100644 index 0000000..33a69df --- /dev/null +++ b/django_template/apps/core/templates/apps/core/index.html @@ -0,0 +1,7 @@ +{% extends 'Baselayout.html' %} + +{% block title %}Home{% endblock %} + +{% block content %} +Welcome to your Django project. +{% endblock %} \ No newline at end of file diff --git a/django_template/apps/core/tests.py b/django_template/apps/core/tests.py new file mode 100644 index 0000000..f688862 --- /dev/null +++ b/django_template/apps/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Write tests here. \ No newline at end of file diff --git a/django_template/apps/core/urls.py b/django_template/apps/core/urls.py new file mode 100644 index 0000000..35f595f --- /dev/null +++ b/django_template/apps/core/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + + +urlpatterns = [ + path('', views.IndexView.as_view(), name='index'), +] \ No newline at end of file diff --git a/django_template/apps/core/views.py b/django_template/apps/core/views.py new file mode 100644 index 0000000..fa23806 --- /dev/null +++ b/django_template/apps/core/views.py @@ -0,0 +1,5 @@ +from django.views.generic import TemplateView + + +class IndexView(TemplateView): + template_name = 'apps/core/index.html' \ No newline at end of file diff --git a/django_template/manage.py b/django_template/manage.py new file mode 100644 index 0000000..c656995 --- /dev/null +++ b/django_template/manage.py @@ -0,0 +1,22 @@ +#!/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() \ No newline at end of file diff --git a/django_template/project_name/asgi.py b/django_template/project_name/asgi.py new file mode 100644 index 0000000..5dcc8d8 --- /dev/null +++ b/django_template/project_name/asgi.py @@ -0,0 +1,10 @@ +"""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() \ No newline at end of file diff --git a/django_template/project_name/settings.py b/django_template/project_name/settings.py new file mode 100644 index 0000000..b50dbdc --- /dev/null +++ b/django_template/project_name/settings.py @@ -0,0 +1,84 @@ +"""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' \ No newline at end of file diff --git a/django_template/project_name/urls.py b/django_template/project_name/urls.py new file mode 100644 index 0000000..da5acbb --- /dev/null +++ b/django_template/project_name/urls.py @@ -0,0 +1,15 @@ +"""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) \ No newline at end of file diff --git a/django_template/project_name/wsgi.py b/django_template/project_name/wsgi.py new file mode 100644 index 0000000..b96fdd1 --- /dev/null +++ b/django_template/project_name/wsgi.py @@ -0,0 +1,10 @@ +"""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() \ No newline at end of file diff --git a/django_template/static/css/styles.css b/django_template/static/css/styles.css new file mode 100644 index 0000000..082990e --- /dev/null +++ b/django_template/static/css/styles.css @@ -0,0 +1,10 @@ +body { + margin: 0; + font-family: sans-serif; +} + +.container { + margin: 0 auto; + max-width: 960px; + padding: 2rem; +} \ No newline at end of file diff --git a/django_template/templates/Baselayout.html b/django_template/templates/Baselayout.html new file mode 100644 index 0000000..c1a03b6 --- /dev/null +++ b/django_template/templates/Baselayout.html @@ -0,0 +1,15 @@ +{% load static %} + + +
+ + + +