this repo has no description

Initial commit (partway through tut)

db.sqlite3

This is a binary file and will not be displayed.

+22
manage.py
··· 1 + #!/usr/bin/env python 2 + """Django's command-line utility for administrative tasks.""" 3 + import os 4 + import sys 5 + 6 + 7 + def main(): 8 + """Run administrative tasks.""" 9 + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 10 + try: 11 + from django.core.management import execute_from_command_line 12 + except ImportError as exc: 13 + raise ImportError( 14 + "Couldn't import Django. Are you sure it's installed and " 15 + "available on your PYTHONPATH environment variable? Did you " 16 + "forget to activate a virtual environment?" 17 + ) from exc 18 + execute_from_command_line(sys.argv) 19 + 20 + 21 + if __name__ == '__main__': 22 + main()
mysite/__init__.py

This is a binary file and will not be displayed.

mysite/__pycache__/__init__.cpython-313.pyc

This is a binary file and will not be displayed.

mysite/__pycache__/settings.cpython-313.pyc

This is a binary file and will not be displayed.

mysite/__pycache__/urls.cpython-313.pyc

This is a binary file and will not be displayed.

mysite/__pycache__/wsgi.cpython-313.pyc

This is a binary file and will not be displayed.

+16
mysite/asgi.py
··· 1 + """ 2 + ASGI config for mysite project. 3 + 4 + It exposes the ASGI callable as a module-level variable named ``application``. 5 + 6 + For more information on this file, see 7 + https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ 8 + """ 9 + 10 + import os 11 + 12 + from django.core.asgi import get_asgi_application 13 + 14 + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 + 16 + application = get_asgi_application()
+123
mysite/settings.py
··· 1 + """ 2 + Django settings for mysite project. 3 + 4 + Generated by 'django-admin startproject' using Django 5.2.5. 5 + 6 + For more information on this file, see 7 + https://docs.djangoproject.com/en/5.2/topics/settings/ 8 + 9 + For the full list of settings and their values, see 10 + https://docs.djangoproject.com/en/5.2/ref/settings/ 11 + """ 12 + 13 + from pathlib import Path 14 + 15 + # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 + BASE_DIR = Path(__file__).resolve().parent.parent 17 + 18 + 19 + # Quick-start development settings - unsuitable for production 20 + # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ 21 + 22 + # SECURITY WARNING: keep the secret key used in production secret! 23 + SECRET_KEY = 'django-insecure-$9ndz3ry46wlt-5oxf5j%6)5l-4*3^#b@tqxkj%*1elavkm13j' 24 + 25 + # SECURITY WARNING: don't run with debug turned on in production! 26 + DEBUG = True 27 + 28 + ALLOWED_HOSTS = [] 29 + 30 + 31 + # Application definition 32 + 33 + INSTALLED_APPS = [ 34 + 'polls.apps.PollsConfig', 35 + 'django.contrib.admin', 36 + 'django.contrib.auth', 37 + 'django.contrib.contenttypes', 38 + 'django.contrib.sessions', 39 + 'django.contrib.messages', 40 + 'django.contrib.staticfiles', 41 + ] 42 + 43 + MIDDLEWARE = [ 44 + 'django.middleware.security.SecurityMiddleware', 45 + 'django.contrib.sessions.middleware.SessionMiddleware', 46 + 'django.middleware.common.CommonMiddleware', 47 + 'django.middleware.csrf.CsrfViewMiddleware', 48 + 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 + 'django.contrib.messages.middleware.MessageMiddleware', 50 + 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 + ] 52 + 53 + ROOT_URLCONF = 'mysite.urls' 54 + 55 + TEMPLATES = [ 56 + { 57 + 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 + 'DIRS': [], 59 + 'APP_DIRS': True, 60 + 'OPTIONS': { 61 + 'context_processors': [ 62 + 'django.template.context_processors.request', 63 + 'django.contrib.auth.context_processors.auth', 64 + 'django.contrib.messages.context_processors.messages', 65 + ], 66 + }, 67 + }, 68 + ] 69 + 70 + WSGI_APPLICATION = 'mysite.wsgi.application' 71 + 72 + 73 + # Database 74 + # https://docs.djangoproject.com/en/5.2/ref/settings/#databases 75 + 76 + DATABASES = { 77 + 'default': { 78 + 'ENGINE': 'django.db.backends.sqlite3', 79 + 'NAME': BASE_DIR / 'db.sqlite3', 80 + } 81 + } 82 + 83 + 84 + # Password validation 85 + # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators 86 + 87 + AUTH_PASSWORD_VALIDATORS = [ 88 + { 89 + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 90 + }, 91 + { 92 + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 93 + }, 94 + { 95 + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 96 + }, 97 + { 98 + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 99 + }, 100 + ] 101 + 102 + 103 + # Internationalization 104 + # https://docs.djangoproject.com/en/5.2/topics/i18n/ 105 + 106 + LANGUAGE_CODE = 'en-us' 107 + 108 + TIME_ZONE = 'America/New_York' 109 + 110 + USE_I18N = True 111 + 112 + USE_TZ = True 113 + 114 + 115 + # Static files (CSS, JavaScript, Images) 116 + # https://docs.djangoproject.com/en/5.2/howto/static-files/ 117 + 118 + STATIC_URL = 'static/' 119 + 120 + # Default primary key field type 121 + # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field 122 + 123 + DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+23
mysite/urls.py
··· 1 + """ 2 + URL configuration for mysite project. 3 + 4 + The `urlpatterns` list routes URLs to views. For more information please see: 5 + https://docs.djangoproject.com/en/5.2/topics/http/urls/ 6 + Examples: 7 + Function views 8 + 1. Add an import: from my_app import views 9 + 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 + Class-based views 11 + 1. Add an import: from other_app.views import Home 12 + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 + Including another URLconf 14 + 1. Import the include() function: from django.urls import include, path 15 + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 + """ 17 + from django.contrib import admin 18 + from django.urls import include, path 19 + 20 + urlpatterns = [ 21 + path("polls/", include("polls.urls")), 22 + path('admin/', admin.site.urls), 23 + ]
+16
mysite/wsgi.py
··· 1 + """ 2 + WSGI config for mysite project. 3 + 4 + It exposes the WSGI callable as a module-level variable named ``application``. 5 + 6 + For more information on this file, see 7 + https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ 8 + """ 9 + 10 + import os 11 + 12 + from django.core.wsgi import get_wsgi_application 13 + 14 + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') 15 + 16 + application = get_wsgi_application()
polls/__init__.py

This is a binary file and will not be displayed.

polls/__pycache__/__init__.cpython-313.pyc

This is a binary file and will not be displayed.

polls/__pycache__/admin.cpython-313.pyc

This is a binary file and will not be displayed.

polls/__pycache__/apps.cpython-313.pyc

This is a binary file and will not be displayed.

polls/__pycache__/models.cpython-313.pyc

This is a binary file and will not be displayed.

polls/__pycache__/urls.cpython-313.pyc

This is a binary file and will not be displayed.

polls/__pycache__/views.cpython-313.pyc

This is a binary file and will not be displayed.

+7
polls/admin.py
··· 1 + from django.contrib import admin 2 + 3 + from .models import Question 4 + 5 + # Register your models here. 6 + 7 + admin.site.register(Question)
+6
polls/apps.py
··· 1 + from django.apps import AppConfig 2 + 3 + 4 + class PollsConfig(AppConfig): 5 + default_auto_field = 'django.db.models.BigAutoField' 6 + name = 'polls'
+32
polls/migrations/0001_initial.py
··· 1 + # Generated by Django 5.2.5 on 2025-08-23 00:30 2 + 3 + import django.db.models.deletion 4 + from django.db import migrations, models 5 + 6 + 7 + class Migration(migrations.Migration): 8 + 9 + initial = True 10 + 11 + dependencies = [ 12 + ] 13 + 14 + operations = [ 15 + migrations.CreateModel( 16 + name='Question', 17 + fields=[ 18 + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 + ('question_text', models.CharField(max_length=200)), 20 + ('pub_date', models.DateTimeField(verbose_name='date published')), 21 + ], 22 + ), 23 + migrations.CreateModel( 24 + name='Choice', 25 + fields=[ 26 + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 27 + ('choice_text', models.CharField(max_length=200)), 28 + ('votes', models.IntegerField(default=0)), 29 + ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')), 30 + ], 31 + ), 32 + ]
polls/migrations/__init__.py

This is a binary file and will not be displayed.

polls/migrations/__pycache__/0001_initial.cpython-313.pyc

This is a binary file and will not be displayed.

polls/migrations/__pycache__/__init__.cpython-313.pyc

This is a binary file and will not be displayed.

+26
polls/models.py
··· 1 + import datetime 2 + 3 + from django.db import models 4 + from django.utils import timezone 5 + 6 + # Create your models here. 7 + 8 + class Question(models.Model): 9 + question_text = models.CharField(max_length=200) 10 + pub_date = models.DateTimeField("date published") 11 + 12 + def __str__(self): 13 + return self.question_text 14 + 15 + def was_published_recently(self): 16 + return self.pub_date > timezone.now() - datetime.timedelta(days=1) 17 + 18 + 19 + 20 + class Choice(models.Model): 21 + question = models.ForeignKey(Question, on_delete=models.CASCADE) 22 + choice_text = models.CharField(max_length=200) 23 + votes = models.IntegerField(default=0) 24 + 25 + def __str__(self): 26 + return self.choice_text
+11
polls/templates/polls/index.html
··· 1 + {% if latest_question_list %} 2 + <ul> 3 + {% for question in latest_question_list %} 4 + <li> 5 + <a href="/polls/{{question.id}}/"> {{ question.question_text }} </a> 6 + </li> 7 + {% endfor %} 8 + </ul> 9 + {% else%} 10 + <p>No polls are available.</p> 11 + {% endif %}
+3
polls/tests.py
··· 1 + from django.test import TestCase 2 + 3 + # Create your tests here.
+14
polls/urls.py
··· 1 + from django.urls import path 2 + 3 + from . import views 4 + 5 + urlpatterns = [ 6 + # ex: /polls/ 7 + path("", views.index, name="index"), 8 + # ex: /polls/5/ 9 + path("<int:question_id>/", views.detail, name="detail"), 10 + # ex: /polls/5/results/ 11 + path("<int:question_id>/results/", views.results, name="results"), 12 + # ex: /polls/5/vote/ 13 + path("<int:question_id>/vote/", views.vote, name="vote") 14 + ]
+28
polls/views.py
··· 1 + from django.http import HttpResponse, Http404 2 + from django.shortcuts import render 3 + 4 + from .models import Question 5 + 6 + # Create your views here. 7 + 8 + def index(request): 9 + ### Longer version using template and loader. "render" shortcuts this. 10 + # latest_question_list = Question.objects.order_by("-pub_date")[:5] 11 + # template = loader.get_template("polls/index.html") 12 + # context = {"latest_question_list": latest_question_list} 13 + # return HttpResponse(template.render(context, request)) 14 + 15 + latest_question_list = Question.objects.order_by("-pub_date")[:5] 16 + context = {"latest_question_list": latest_question_list} 17 + return render(request, "polls/index.html", context) 18 + 19 + 20 + def detail(request, question_id): 21 + return HttpResponse("You're looking at question %s." % question_id) 22 + 23 + def results(request, question_id): 24 + response = "You're looking at the results of question %s." 25 + return HttpResponse(response % question_id) 26 + 27 + def vote(request, question_id): 28 + return HttpResponse("You're voting on question %s." % question_id)