diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/manage.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/manage.py" new file mode 100644 index 0000000000000000000000000000000000000000..dbfc95f778932d75bf40743b53575c4d2daf8adb --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/manage.py" @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.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) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/__init__.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/__init__.py" new file mode 100644 index 0000000000000000000000000000000000000000..bc6c8fb2a5e57539f0cef688a64d44aa88fae1b4 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/__init__.py" @@ -0,0 +1,3 @@ +import pymysql + +pymysql.install_as_MySQLdb() \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..63c7f4f37127bedbbedebe3217e0182d6dc63613 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/settings.py" @@ -0,0 +1,125 @@ +""" +Django settings for mysite project. + +Generated by 'django-admin startproject' using Django 2.0. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '2e2b)3#ns0$=6&coz7+kjl9ydhatl^n8rrtoviape4_yari*he' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'polls.apps.PollsConfig', + '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 = 'mysite.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'mysite.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'polls', + 'USER': 'root', + 'PASSWORD': 'zxy961231', + 'HOST': '127.0.0.1', + 'PORT': '3306' + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/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/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..0fcbe1e1c24825cc54b1a154b70b982e86bf087b --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/urls.py" @@ -0,0 +1,22 @@ +"""mysite URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/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('polls/', include('polls.urls')), + path('admin/', admin.site.urls), +] diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/wsgi.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/wsgi.py" new file mode 100644 index 0000000000000000000000000000000000000000..f4963bc7803bb09fab0c3cceec0afa445379dbb6 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/mysite/wsgi.py" @@ -0,0 +1,16 @@ +""" +WSGI config for mysite 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/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") + +application = get_wsgi_application() diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/__init__.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/__init__.py" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/admin.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/admin.py" new file mode 100644 index 0000000000000000000000000000000000000000..7a51043099f24f440e566e9736dc270542561b95 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/admin.py" @@ -0,0 +1,6 @@ +from django.contrib import admin + +# Register your models here. +from .models import Question, Choice +admin.site.register(Question) +admin.site.register(Choice) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/apps.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/apps.py" new file mode 100644 index 0000000000000000000000000000000000000000..c46d01b8336a0d854174ae0800c4a8cf94f5bd89 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/apps.py" @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class PollsConfig(AppConfig): + name = 'polls' diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/0001_initial.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/0001_initial.py" new file mode 100644 index 0000000000000000000000000000000000000000..322f1e64b9364fd5656291578eeb57264776e0b9 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/0001_initial.py" @@ -0,0 +1,36 @@ +# Generated by Django 2.0 on 2021-03-26 15:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Choice', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('choice_text', models.CharField(max_length=200)), + ('votes', models.IntegerField(default=0)), + ], + ), + migrations.CreateModel( + name='Question', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('question_text', models.CharField(max_length=200)), + ('pub_data', models.DateTimeField(verbose_name='date published')), + ], + ), + migrations.AddField( + model_name='choice', + name='question', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Question'), + ), + ] diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/0002_auto_20210328_0942.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/0002_auto_20210328_0942.py" new file mode 100644 index 0000000000000000000000000000000000000000..9422d8e23e49d71f18894ebcc2b30cb3e9434fb2 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/0002_auto_20210328_0942.py" @@ -0,0 +1,18 @@ +# Generated by Django 2.0 on 2021-03-28 01:42 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('polls', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='question', + old_name='pub_data', + new_name='pub_date', + ), + ] diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/__init__.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/migrations/__init__.py" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/models.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/models.py" new file mode 100644 index 0000000000000000000000000000000000000000..8e60067823e29dd4aec1cc8b3fc21c6228a56719 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/models.py" @@ -0,0 +1,12 @@ +from django.db import models + +# Create your models here. + +class Question(models.Model): + question_text = models.CharField(max_length=200) + pub_date = models.DateTimeField('date published') + +class Choice(models.Model): + question = models.ForeignKey(Question,on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + votes = models.IntegerField(default=0) diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/detail.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/detail.html" new file mode 100644 index 0000000000000000000000000000000000000000..38e66fd5a17a94c715dd5d0fcc6a179380469771 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/detail.html" @@ -0,0 +1,12 @@ +

{{ question.question_text }}

+ +{% if error_message %}

{{ error_message }}

{% endif %} + +
+{% csrf_token %} +{% for choice in question.choice_set.all %} + +
+{% endfor %} + +
\ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/index.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/index.html" new file mode 100644 index 0000000000000000000000000000000000000000..6547813510c41fce5347f8a9c6de15b2687809b3 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/index.html" @@ -0,0 +1,9 @@ +{% if latest_question_list %} + +{% else %} +

No polls are available.

+{% endif %} \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/results.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/results.html" new file mode 100644 index 0000000000000000000000000000000000000000..24c1e0c1b092922e09134b91074668913278e0e6 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/templates/polls/results.html" @@ -0,0 +1,9 @@ +

{{ question.question_text }}

+ + + +Vote again? \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/tests.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/tests.py" new file mode 100644 index 0000000000000000000000000000000000000000..de8bdc00eb2fed53494a534d48e400faa830dbd9 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/tests.py" @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..d7871ffc8b78698322e760620b90ef9b7a4e7217 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/urls.py" @@ -0,0 +1,15 @@ +from django.contrib import admin +from . import views +from django.urls import path + +app_name = 'polls' +urlpatterns = [ + # ex: /polls/ + path('', views.IndexView.as_view(), name='index'), + # ex: /polls/5/ + path('/', views.detail, name='detail'), + # ex: /polls/5/results/ + path('/results/', views.results, name='results'), + # ex: /polls/5/vote/ + path('/vote/', views.vote, name='vote'), +] diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/views.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/views.py" new file mode 100644 index 0000000000000000000000000000000000000000..5db4f11c2ff3e385b7c8c72874ba7d451d6b2d85 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/5\347\217\255/5\347\217\255_\345\274\240\345\205\264\351\233\250/\347\254\254\345\215\201\344\270\211\345\221\250 3.22-3.28/\344\272\214\344\270\211\350\212\202,/polls/views.py" @@ -0,0 +1,63 @@ +from django.shortcuts import render,get_object_or_404 +from django.http import HttpResponse, Http404, HttpResponseRedirect +from .models import Question, Choice +from django.urls import reverse +from django.views import generic +# Create your views here. + +# 通用视图 +class IndexView(generic.TemplateView): + template_name = 'polls/index.html' + + def get_context_data(self, **kwargs): + latest_question_list = Question.objects.order_by('-pub_date')[:5] + context = { + 'latest_question_list': latest_question_list, + } + return context + +def index(request): + + """ + request 就是作为参数传进来的请求对象 + :param request: + :return: HttpResponse 处理完请求的返回对象 + """ + latest_question_list = Question.objects.order_by('-pub_date')[:5] + context = { + 'latest_question_list': latest_question_list, + } + return render(request,'polls/index.html', context) + +def detail(request, question_id): + try: + question = Question.objects.get(pk=question_id) + context = { + "question":question + } + except Question.DoesNotExist: + raise Http404("Question does not exist") + return render(request,'polls/detail.html', context) + + +def results(request, question_id): + question = get_object_or_404(Question, pk=question_id) + return render(request, 'polls/results.html', {'question': question}) + +def vote(request, question_id): + question = get_object_or_404(Question, pk=question_id) + try: + selected_choice = question.choice_set.get(pk=request.POST['choice']) + except (KeyError, Choice.DoesNotExist): + # Redisplay the question voting form. + return render(request, 'polls/detail.html', { + 'question': question, + 'error_message': "You didn't select a choice.", + }) + else: + selected_choice.votes += 1 + selected_choice.save() + # Always return an HttpResponseRedirect after successfully dealing + # with POST data. This prevents data from being posted twice if a + # user hits the Back button. + return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) \ No newline at end of file