Django-编写Views.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django-编写Views.py相关的知识,希望对你有一定的参考价值。
polls/views.py
views中定义三个方法
def detail(request, question_id): return HttpResponse("You‘re looking at question %s." % question_id) def results(request, question_id): response = "You‘re looking at the results of question %s." return HttpResponse(response % question_id) def vote(request, question_id): return HttpResponse("You‘re voting on question %s." % question_id)
polls/urls.py
urls触发views定义三个方法
from django.conf.urls import url from . import views urlpatterns = [ # ex: /polls/ url(r‘^$‘, views.index, name=‘index‘), # ex: /polls/5/ url(r‘^(?P<question_id>[0-9]+)/$‘, views.detail, name=‘detail‘), # ex: /polls/5/results/ url(r‘^(?P<question_id>[0-9]+)/results/$‘, views.results, name=‘results‘), # ex: /polls/5/vote/ url(r‘^(?P<question_id>[0-9]+)/vote/$‘, views.vote, name=‘vote‘), ]
以上是关于Django-编写Views.py的主要内容,如果未能解决你的问题,请参考以下文章