diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/config/__pycache__/__init__.cpython-312.pyc b/config/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 00000000000..1ca24b88fc9 Binary files /dev/null and b/config/__pycache__/__init__.cpython-312.pyc differ diff --git a/config/__pycache__/settings.cpython-312.pyc b/config/__pycache__/settings.cpython-312.pyc new file mode 100644 index 00000000000..bdcb8863a4d Binary files /dev/null and b/config/__pycache__/settings.cpython-312.pyc differ diff --git a/config/__pycache__/urls.cpython-312.pyc b/config/__pycache__/urls.cpython-312.pyc new file mode 100644 index 00000000000..c5f10c4ba4f Binary files /dev/null and b/config/__pycache__/urls.cpython-312.pyc differ diff --git a/config/__pycache__/wsgi.cpython-312.pyc b/config/__pycache__/wsgi.cpython-312.pyc new file mode 100644 index 00000000000..9b917300cf3 Binary files /dev/null and b/config/__pycache__/wsgi.cpython-312.pyc differ diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 00000000000..cd6907c72e1 --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config 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", "config.settings") + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 00000000000..e47ef9b403d --- /dev/null +++ b/config/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 5.2.7. + +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-azg3-b&7n&2tq)xbefu1%$85#(8scs67xz2964%u-iz3=$3r1(" + +# 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", + "trydjango", + "products", # <-- must be here +] +# also check: +# ROOT_URLCONF = 'config.urls' + + +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 = "config.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 = "config.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/config/urls.py b/config/urls.py new file mode 100644 index 00000000000..65d226e9eea --- /dev/null +++ b/config/urls.py @@ -0,0 +1,26 @@ +""" +URL configuration for config 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, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('products.urls')), # ← connect app urls here +] + + diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 00000000000..27c0377235b --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config 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", "config.settings") + +application = get_wsgi_application() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 00000000000..5ba26f08254 Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100755 index 00000000000..d28672eaec0 --- /dev/null +++ b/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", "config.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/products/__init__.py b/products/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/products/__pycache__/__init__.cpython-312.pyc b/products/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 00000000000..c409abfadc5 Binary files /dev/null and b/products/__pycache__/__init__.cpython-312.pyc differ diff --git a/products/__pycache__/admin.cpython-312.pyc b/products/__pycache__/admin.cpython-312.pyc new file mode 100644 index 00000000000..6c64b0c9925 Binary files /dev/null and b/products/__pycache__/admin.cpython-312.pyc differ diff --git a/products/__pycache__/apps.cpython-312.pyc b/products/__pycache__/apps.cpython-312.pyc new file mode 100644 index 00000000000..42e51bc0248 Binary files /dev/null and b/products/__pycache__/apps.cpython-312.pyc differ diff --git a/products/__pycache__/models.cpython-312.pyc b/products/__pycache__/models.cpython-312.pyc new file mode 100644 index 00000000000..67fe8f73420 Binary files /dev/null and b/products/__pycache__/models.cpython-312.pyc differ diff --git a/products/__pycache__/urls.cpython-312.pyc b/products/__pycache__/urls.cpython-312.pyc new file mode 100644 index 00000000000..d3867e14a8a Binary files /dev/null and b/products/__pycache__/urls.cpython-312.pyc differ diff --git a/products/__pycache__/views.cpython-312.pyc b/products/__pycache__/views.cpython-312.pyc new file mode 100644 index 00000000000..ae21475cc88 Binary files /dev/null and b/products/__pycache__/views.cpython-312.pyc differ diff --git a/products/admin.py b/products/admin.py new file mode 100644 index 00000000000..972d8c20185 --- /dev/null +++ b/products/admin.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from .models import Product + +@admin.register(Product) +class ProductAdmin(admin.ModelAdmin): + list_display = ("id", "title", "price", "featured") + list_filter = ("featured",) + search_fields = ("title", "description") + diff --git a/products/apps.py b/products/apps.py new file mode 100644 index 00000000000..7b0ca83a6d0 --- /dev/null +++ b/products/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ProductsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "products" diff --git a/products/migrations/0001_initial.py b/products/migrations/0001_initial.py new file mode 100644 index 00000000000..4c1846270bc --- /dev/null +++ b/products/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 5.2.7 on 2025-10-23 21:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Product", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=120)), + ("description", models.TextField(blank=True, null=True)), + ("price", models.DecimalField(decimal_places=2, max_digits=10000)), + ("summary", models.TextField(blank=True, default="this is cool!")), + ("featured", models.BooleanField(default=False)), + ], + ), + ] diff --git a/products/migrations/__init__.py b/products/migrations/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/products/migrations/__pycache__/0001_initial.cpython-312.pyc b/products/migrations/__pycache__/0001_initial.cpython-312.pyc new file mode 100644 index 00000000000..036a941972d Binary files /dev/null and b/products/migrations/__pycache__/0001_initial.cpython-312.pyc differ diff --git a/products/migrations/__pycache__/__init__.cpython-312.pyc b/products/migrations/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 00000000000..ab5bfb519ea Binary files /dev/null and b/products/migrations/__pycache__/__init__.cpython-312.pyc differ diff --git a/products/models.py b/products/models.py new file mode 100644 index 00000000000..de979b56faf --- /dev/null +++ b/products/models.py @@ -0,0 +1,14 @@ +from django.db import models + +class Product(models.Model): + title = models.CharField(max_length=120) + description = models.TextField(blank=True, null=True) + price = models.DecimalField(decimal_places=2, max_digits=10000) + summary = models.TextField(default="this is cool!", blank=True) + featured = models.BooleanField(default=False) + + + + def __str__(self): + return self.title + diff --git a/products/templates/base.html b/products/templates/base.html new file mode 100644 index 00000000000..12ff4f97906 --- /dev/null +++ b/products/templates/base.html @@ -0,0 +1,20 @@ + + +
+ +Now using a template ✅
+{% endblock %} diff --git a/products/templates/products/list.html b/products/templates/products/list.html new file mode 100644 index 00000000000..4411f6307a5 --- /dev/null +++ b/products/templates/products/list.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block content %} +No products yet.
+ {% endif %} +{% endblock %} + diff --git a/products/tests.py b/products/tests.py new file mode 100644 index 00000000000..7ce503c2dd9 --- /dev/null +++ b/products/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/products/urls.py b/products/urls.py new file mode 100644 index 00000000000..ef1cc806cdc --- /dev/null +++ b/products/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.home_view, name='home'), + path('products/', views.product_list_view, name='product-list'), +] diff --git a/products/views.py b/products/views.py new file mode 100644 index 00000000000..e378b8c132e --- /dev/null +++ b/products/views.py @@ -0,0 +1,11 @@ +from django.shortcuts import render +from .models import Product + +def home_view(request): + return render(request, "home.html", {"title": "Home"}) + +def product_list_view(request): + products = Product.objects.all() + return render(request, "products/list.html", {"products": products, "title": "Products"}) + + diff --git a/trydjango/__pycache__/urls.cpython-312.pyc b/trydjango/__pycache__/urls.cpython-312.pyc new file mode 100644 index 00000000000..1632d8e6653 Binary files /dev/null and b/trydjango/__pycache__/urls.cpython-312.pyc differ diff --git a/trydjango/__pycache__/views.cpython-312.pyc b/trydjango/__pycache__/views.cpython-312.pyc new file mode 100644 index 00000000000..965f8be1aa7 Binary files /dev/null and b/trydjango/__pycache__/views.cpython-312.pyc differ diff --git a/trydjango/config/__init__.py b/trydjango/config/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/trydjango/config/asgi.py b/trydjango/config/asgi.py new file mode 100644 index 00000000000..cd6907c72e1 --- /dev/null +++ b/trydjango/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config 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", "config.settings") + +application = get_asgi_application() diff --git a/trydjango/config/settings.py b/trydjango/config/settings.py new file mode 100644 index 00000000000..abae679359f --- /dev/null +++ b/trydjango/config/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 5.2.7. + +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-b&))&^&fbrahm$a2ye$ml2-!0nrpjne7rxg=09lij46)mj4!wn" + +# 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 = "config.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 = "config.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/trydjango/config/urls.py b/trydjango/config/urls.py new file mode 100644 index 00000000000..bdec395e71b --- /dev/null +++ b/trydjango/config/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for config 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/trydjango/config/wsgi.py b/trydjango/config/wsgi.py new file mode 100644 index 00000000000..27c0377235b --- /dev/null +++ b/trydjango/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config 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", "config.settings") + +application = get_wsgi_application() diff --git a/trydjango/db.sqlite3 b/trydjango/db.sqlite3 new file mode 100644 index 00000000000..6f0ac9ca564 Binary files /dev/null and b/trydjango/db.sqlite3 differ diff --git a/trydjango/manage.py b/trydjango/manage.py new file mode 100755 index 00000000000..d28672eaec0 --- /dev/null +++ b/trydjango/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", "config.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/trydjango/urls.py b/trydjango/urls.py new file mode 100644 index 00000000000..960fe9dc609 --- /dev/null +++ b/trydjango/urls.py @@ -0,0 +1,8 @@ + +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.home, name='home'), + +] diff --git a/trydjango/views.py b/trydjango/views.py new file mode 100644 index 00000000000..f8d6312e861 --- /dev/null +++ b/trydjango/views.py @@ -0,0 +1,4 @@ +from django.http import HttpResponse + +def home(request): + return HttpResponse("Hello! This is my TryDjango app.") diff --git a/urls.py b/urls.py new file mode 100644 index 00000000000..e69de29bb2d