diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /admin.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /admin.py" new file mode 100644 index 0000000000000000000000000000000000000000..63a9bebb19afdf8ecfdd065ef303c7edd85dba52 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /admin.py" @@ -0,0 +1,8 @@ +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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /detail.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /index.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /results.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..fad1b03977b657e30b45b3f47879e12d7daf60cd --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /settings.py" @@ -0,0 +1,126 @@ +""" +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 = 'epfv*#g3ppeyu6m41c23@cfzn45qi-k5&*r76rysp7!c!62uzo' + +# 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': 'lmc.123', + '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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..7e3d48243e1176ded107189286f8b8bfbceba08c --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /urls.py" @@ -0,0 +1,14 @@ +from django.urls import path +from . import views + +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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /views.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /views.py" new file mode 100644 index 0000000000000000000000000000000000000000..282ba9129857bcd11ca3531637fea61f220afcb0 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\270\211\350\212\202 /views.py" @@ -0,0 +1,62 @@ +from django.shortcuts import render, get_object_or_404 +from django.http import HttpResponse, Http404, HttpResponseRedirect +from django.urls import reverse +from django.views import generic +from .models import Question, Choice +# 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: + """ + 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",) + +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 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /__init__.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /__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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /apps.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /models.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /models.py" new file mode 100644 index 0000000000000000000000000000000000000000..0bd0fe17f909ac0ca7964c5e05ee3a7f24332b44 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /models.py" @@ -0,0 +1,14 @@ +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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..c290a211336f56f6a494b155070b007ce8fd08fd --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\270\211\345\221\250 /\347\254\254\345\215\201\344\270\211\345\221\250_\347\254\254\344\272\214\350\212\202 /urls.py" @@ -0,0 +1,14 @@ +from django.urls import path +from . import views + +app_name = 'polls' +urlpatterns = [ + # ex: /polls/ + path('', views.index, 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'), +]