From ef759da0b903690e7be545a27c91945dfd666b7b Mon Sep 17 00:00:00 2001 From: martin-martin Date: Mon, 24 Nov 2025 10:23:39 +0100 Subject: [PATCH 1/6] Add materials for django setup tutorial --- create-django-project/README.md | 43 ++++++ create-django-project/pyproject.toml | 7 + create-django-project/requirements.txt | 3 + .../setup/example/__init__.py | 0 create-django-project/setup/example/admin.py | 3 + create-django-project/setup/example/apps.py | 6 + .../setup/example/migrations/__init__.py | 0 create-django-project/setup/example/models.py | 3 + create-django-project/setup/example/tests.py | 3 + create-django-project/setup/example/views.py | 3 + create-django-project/setup/manage.py | 22 ++++ create-django-project/setup/setup/__init__.py | 0 create-django-project/setup/setup/asgi.py | 16 +++ create-django-project/setup/setup/settings.py | 122 ++++++++++++++++++ create-django-project/setup/setup/urls.py | 23 ++++ create-django-project/setup/setup/wsgi.py | 16 +++ 16 files changed, 270 insertions(+) create mode 100644 create-django-project/README.md create mode 100644 create-django-project/pyproject.toml create mode 100644 create-django-project/requirements.txt create mode 100644 create-django-project/setup/example/__init__.py create mode 100644 create-django-project/setup/example/admin.py create mode 100644 create-django-project/setup/example/apps.py create mode 100644 create-django-project/setup/example/migrations/__init__.py create mode 100644 create-django-project/setup/example/models.py create mode 100644 create-django-project/setup/example/tests.py create mode 100644 create-django-project/setup/example/views.py create mode 100755 create-django-project/setup/manage.py create mode 100644 create-django-project/setup/setup/__init__.py create mode 100644 create-django-project/setup/setup/asgi.py create mode 100644 create-django-project/setup/setup/settings.py create mode 100644 create-django-project/setup/setup/urls.py create mode 100644 create-django-project/setup/setup/wsgi.py diff --git a/create-django-project/README.md b/create-django-project/README.md new file mode 100644 index 0000000000..b956ff204b --- /dev/null +++ b/create-django-project/README.md @@ -0,0 +1,43 @@ +# How to Create a Django Project + +Follow tutorial on [How to Create a Django Project](https://realpython.com/django-setup/) on Real Python to create a new Django project with one Django app from scratch. + +> **Note:** This project targets Python 3.10 or later. + +## Setup + +You can run the provided example project on your local machine by following the steps outlined below. + +Create a new virtual environment: + +```bash +$ python3 -m venv venv +``` + +Activate the virtual environment: + +```bash +$ source venv/bin/activate +``` + +Install the dependencies for this project: + +```bash +(venv) $ python -m pip install -r requirements.txt +``` + +## Run the Scaffold + +Navigate into the Django project folder: + +```bash +(venv) $ cd setup +``` + +Run the Django development server: + +```bash +(venv) $ python manage.py runserver +``` + +Navigate to `http://localhost:8000/` to see the starter project in action. diff --git a/create-django-project/pyproject.toml b/create-django-project/pyproject.toml new file mode 100644 index 0000000000..0cb9df9d01 --- /dev/null +++ b/create-django-project/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "django-setup" +version = "0.1.0" +requires-python = ">=3.10" +dependencies = [ + "django>=5.2.8", +] diff --git a/create-django-project/requirements.txt b/create-django-project/requirements.txt new file mode 100644 index 0000000000..60638a8f70 --- /dev/null +++ b/create-django-project/requirements.txt @@ -0,0 +1,3 @@ +asgiref==3.11.0 +django==5.2.8 +sqlparse==0.5.3 diff --git a/create-django-project/setup/example/__init__.py b/create-django-project/setup/example/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/create-django-project/setup/example/admin.py b/create-django-project/setup/example/admin.py new file mode 100644 index 0000000000..8c38f3f3da --- /dev/null +++ b/create-django-project/setup/example/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/create-django-project/setup/example/apps.py b/create-django-project/setup/example/apps.py new file mode 100644 index 0000000000..21698827cc --- /dev/null +++ b/create-django-project/setup/example/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ExampleConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "example" diff --git a/create-django-project/setup/example/migrations/__init__.py b/create-django-project/setup/example/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/create-django-project/setup/example/models.py b/create-django-project/setup/example/models.py new file mode 100644 index 0000000000..71a8362390 --- /dev/null +++ b/create-django-project/setup/example/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/create-django-project/setup/example/tests.py b/create-django-project/setup/example/tests.py new file mode 100644 index 0000000000..7ce503c2dd --- /dev/null +++ b/create-django-project/setup/example/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/create-django-project/setup/example/views.py b/create-django-project/setup/example/views.py new file mode 100644 index 0000000000..91ea44a218 --- /dev/null +++ b/create-django-project/setup/example/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/create-django-project/setup/manage.py b/create-django-project/setup/manage.py new file mode 100755 index 0000000000..bab32d243c --- /dev/null +++ b/create-django-project/setup/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", "setup.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() diff --git a/create-django-project/setup/setup/__init__.py b/create-django-project/setup/setup/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/create-django-project/setup/setup/asgi.py b/create-django-project/setup/setup/asgi.py new file mode 100644 index 0000000000..04b6738987 --- /dev/null +++ b/create-django-project/setup/setup/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for setup project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "setup.settings") + +application = get_asgi_application() diff --git a/create-django-project/setup/setup/settings.py b/create-django-project/setup/setup/settings.py new file mode 100644 index 0000000000..9d07ec96ba --- /dev/null +++ b/create-django-project/setup/setup/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for setup project. + +Generated by 'django-admin startproject' using Django 5.2.8. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-*!3%6wxj1sa-i6g&&f+!w_jp^@fcuj=t^9wlg*%p=4b_r%f0q6" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +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 = "setup.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "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 = "setup.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +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", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/create-django-project/setup/setup/urls.py b/create-django-project/setup/setup/urls.py new file mode 100644 index 0000000000..b2654a0a01 --- /dev/null +++ b/create-django-project/setup/setup/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for setup project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" + +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path("admin/", admin.site.urls), +] diff --git a/create-django-project/setup/setup/wsgi.py b/create-django-project/setup/setup/wsgi.py new file mode 100644 index 0000000000..05860fd21a --- /dev/null +++ b/create-django-project/setup/setup/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for setup project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "setup.settings") + +application = get_wsgi_application() From 9cbc3c435fadb1d1769505c4624825ef2239edb0 Mon Sep 17 00:00:00 2001 From: martin-martin Date: Mon, 24 Nov 2025 10:39:13 +0100 Subject: [PATCH 2/6] Add noqa to scaffolding for CI --- create-django-project/setup/example/admin.py | 2 +- create-django-project/setup/example/models.py | 2 +- create-django-project/setup/example/tests.py | 2 +- create-django-project/setup/example/views.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/create-django-project/setup/example/admin.py b/create-django-project/setup/example/admin.py index 8c38f3f3da..4fd549025a 100644 --- a/create-django-project/setup/example/admin.py +++ b/create-django-project/setup/example/admin.py @@ -1,3 +1,3 @@ -from django.contrib import admin +from django.contrib import admin # noqa: F401 # Register your models here. diff --git a/create-django-project/setup/example/models.py b/create-django-project/setup/example/models.py index 71a8362390..82c4e7854b 100644 --- a/create-django-project/setup/example/models.py +++ b/create-django-project/setup/example/models.py @@ -1,3 +1,3 @@ -from django.db import models +from django.db import models # noqa: F401 # Create your models here. diff --git a/create-django-project/setup/example/tests.py b/create-django-project/setup/example/tests.py index 7ce503c2dd..e55d689097 100644 --- a/create-django-project/setup/example/tests.py +++ b/create-django-project/setup/example/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +from django.test import TestCase # noqa: F401 # Create your tests here. diff --git a/create-django-project/setup/example/views.py b/create-django-project/setup/example/views.py index 91ea44a218..7a02d1fd0d 100644 --- a/create-django-project/setup/example/views.py +++ b/create-django-project/setup/example/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +from django.shortcuts import render # noqa: F401 # Create your views here. From 0ed329201423e6d5a5c82f6b31a05b99dee8d86f Mon Sep 17 00:00:00 2001 From: martin-martin Date: Mon, 24 Nov 2025 10:41:18 +0100 Subject: [PATCH 3/6] Format scaffolding --- create-django-project/setup/manage.py | 1 + create-django-project/setup/setup/settings.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/create-django-project/setup/manage.py b/create-django-project/setup/manage.py index bab32d243c..b2af5f15ba 100755 --- a/create-django-project/setup/manage.py +++ b/create-django-project/setup/manage.py @@ -1,5 +1,6 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" + import os import sys diff --git a/create-django-project/setup/setup/settings.py b/create-django-project/setup/setup/settings.py index 9d07ec96ba..18380d0d2a 100644 --- a/create-django-project/setup/setup/settings.py +++ b/create-django-project/setup/setup/settings.py @@ -20,7 +20,9 @@ # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-*!3%6wxj1sa-i6g&&f+!w_jp^@fcuj=t^9wlg*%p=4b_r%f0q6" +SECRET_KEY = ( + "django-insecure-*!3%6wxj1sa-i6g&&f+!w_jp^@fcuj=t^9wlg*%p=4b_r%f0q6" +) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True From e817bb8da4fdc5ea73d221dc9aaf38cf4ea26ad6 Mon Sep 17 00:00:00 2001 From: martin-martin Date: Tue, 9 Dec 2025 11:09:20 +0100 Subject: [PATCH 4/6] Update to Django 6 --- create-django-project/pyproject.toml | 4 ++-- create-django-project/requirements.txt | 4 ++-- create-django-project/setup/example/apps.py | 1 - create-django-project/setup/manage.py | 1 - create-django-project/setup/setup/asgi.py | 2 +- create-django-project/setup/setup/settings.py | 23 ++++++++----------- create-django-project/setup/setup/urls.py | 2 +- create-django-project/setup/setup/wsgi.py | 2 +- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/create-django-project/pyproject.toml b/create-django-project/pyproject.toml index 0cb9df9d01..dd7fef6158 100644 --- a/create-django-project/pyproject.toml +++ b/create-django-project/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "django-setup" version = "0.1.0" -requires-python = ">=3.10" +requires-python = ">=3.12" dependencies = [ - "django>=5.2.8", + "django>=6.0", ] diff --git a/create-django-project/requirements.txt b/create-django-project/requirements.txt index 60638a8f70..f375d23a00 100644 --- a/create-django-project/requirements.txt +++ b/create-django-project/requirements.txt @@ -1,3 +1,3 @@ asgiref==3.11.0 -django==5.2.8 -sqlparse==0.5.3 +django==6.0 +sqlparse==0.5.4 diff --git a/create-django-project/setup/example/apps.py b/create-django-project/setup/example/apps.py index 21698827cc..cdbeed7bcc 100644 --- a/create-django-project/setup/example/apps.py +++ b/create-django-project/setup/example/apps.py @@ -2,5 +2,4 @@ class ExampleConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" name = "example" diff --git a/create-django-project/setup/manage.py b/create-django-project/setup/manage.py index b2af5f15ba..bab32d243c 100755 --- a/create-django-project/setup/manage.py +++ b/create-django-project/setup/manage.py @@ -1,6 +1,5 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" - import os import sys diff --git a/create-django-project/setup/setup/asgi.py b/create-django-project/setup/setup/asgi.py index 04b6738987..308629a25e 100644 --- a/create-django-project/setup/setup/asgi.py +++ b/create-django-project/setup/setup/asgi.py @@ -4,7 +4,7 @@ It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/ """ import os diff --git a/create-django-project/setup/setup/settings.py b/create-django-project/setup/setup/settings.py index 18380d0d2a..6505f79f9c 100644 --- a/create-django-project/setup/setup/settings.py +++ b/create-django-project/setup/setup/settings.py @@ -1,13 +1,13 @@ """ Django settings for setup project. -Generated by 'django-admin startproject' using Django 5.2.8. +Generated by 'django-admin startproject' using Django 6.0. For more information on this file, see -https://docs.djangoproject.com/en/5.2/topics/settings/ +https://docs.djangoproject.com/en/6.0/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/5.2/ref/settings/ +https://docs.djangoproject.com/en/6.0/ref/settings/ """ from pathlib import Path @@ -17,11 +17,11 @@ # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = ( - "django-insecure-*!3%6wxj1sa-i6g&&f+!w_jp^@fcuj=t^9wlg*%p=4b_r%f0q6" + "django-insecure-avx+s!jrtg_6%qri+07#1dsa+mxtmk2kdf1cl_mofz*461mkq2" ) # SECURITY WARNING: don't run with debug turned on in production! @@ -72,7 +72,7 @@ # Database -# https://docs.djangoproject.com/en/5.2/ref/settings/#databases +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases DATABASES = { "default": { @@ -83,7 +83,7 @@ # Password validation -# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -102,7 +102,7 @@ # Internationalization -# https://docs.djangoproject.com/en/5.2/topics/i18n/ +# https://docs.djangoproject.com/en/6.0/topics/i18n/ LANGUAGE_CODE = "en-us" @@ -114,11 +114,6 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/5.2/howto/static-files/ +# https://docs.djangoproject.com/en/6.0/howto/static-files/ STATIC_URL = "static/" - -# Default primary key field type -# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/create-django-project/setup/setup/urls.py b/create-django-project/setup/setup/urls.py index b2654a0a01..4aa864acb9 100644 --- a/create-django-project/setup/setup/urls.py +++ b/create-django-project/setup/setup/urls.py @@ -2,7 +2,7 @@ URL configuration for setup project. The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.2/topics/http/urls/ + https://docs.djangoproject.com/en/6.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views diff --git a/create-django-project/setup/setup/wsgi.py b/create-django-project/setup/setup/wsgi.py index 05860fd21a..6178a1d8eb 100644 --- a/create-django-project/setup/setup/wsgi.py +++ b/create-django-project/setup/setup/wsgi.py @@ -4,7 +4,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/ """ import os From 00fd9c7e40464d03f779b1cf5951856c5708fd12 Mon Sep 17 00:00:00 2001 From: martin-martin Date: Tue, 9 Dec 2025 11:10:50 +0100 Subject: [PATCH 5/6] Fix with ruff --- create-django-project/setup/manage.py | 1 + 1 file changed, 1 insertion(+) diff --git a/create-django-project/setup/manage.py b/create-django-project/setup/manage.py index bab32d243c..b2af5f15ba 100755 --- a/create-django-project/setup/manage.py +++ b/create-django-project/setup/manage.py @@ -1,5 +1,6 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" + import os import sys From c54c936408e777a9b29422d8341f9ede263a3204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Zaczy=C5=84ski?= Date: Thu, 18 Dec 2025 14:38:12 +0100 Subject: [PATCH 6/6] Final QA --- create-django-project/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-django-project/README.md b/create-django-project/README.md index b956ff204b..58cd591006 100644 --- a/create-django-project/README.md +++ b/create-django-project/README.md @@ -2,7 +2,7 @@ Follow tutorial on [How to Create a Django Project](https://realpython.com/django-setup/) on Real Python to create a new Django project with one Django app from scratch. -> **Note:** This project targets Python 3.10 or later. +> **Note:** This project targets Python 3.12 or later. ## Setup @@ -31,7 +31,7 @@ Install the dependencies for this project: Navigate into the Django project folder: ```bash -(venv) $ cd setup +(venv) $ cd setup/ ``` Run the Django development server: