增加视图:myApp/views.py
#_*_coding:utf8_*_
from django.shortcuts import HttpResponse
def index(request):
return HttpResponse("你好,欢迎来到投票系统的主页")
def detail(request, question_id):
return HttpResponse('你正在查看问题%s' % question_id)
def results(request, question_id):
response = '你正在查看问题%s的结果'
return HttpResponse(response % question_id)
def vote(request, question_id):
return HttpResponse('你正在给问题%s投票' % question_id)
配置url:myApp/urls.py
#_*_coding:utf8_*_
from django.urls import path
from . import views
urlpatterns = [
# /myApp/
path('', views.index, name='index'),
# /polls/1/
path('<int:question_id>/', views.detail, name='detail'),
# /myApp/1/results/
path('<int:question_id>/results/', views.results, name='results'),
# /myApp/1/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
]