from django.conf.urls import include, url from django.contrib import admin from polls import views urlpatterns = [ url(r‘^admin/‘, include(admin.site.urls)), url(r‘^polls/$‘,views.index,name=‘index‘), url(r‘^polls/(?P<question_id>[0-9]+)/$‘,‘polls.views.detail‘), url(r‘^polls/(?P<question_id>[0-9]+)/results/$‘,views.results,name=‘results‘), url(r‘^polls/(?P<question_id>[0-9]+)/vote/$‘,views.vote,name=‘vote‘), ]
views.py 定义方法
from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(request): return HttpResponse("hello django, you‘re at the polls index.") def detail(request,question_id): return HttpResponse("you are looking at question %s."% question_id) def results(request,question_id): reponse = "you are looking at the results of question %s." return HttpResponse(reponse%question_id) def vote(request,question_id): return HttpResponse("you are voting on question %s."% question_id)
URL设置中 regular expression是一个比较重要的玩意儿 这个得学习好 友情链接:http://deerchao.net/tutorials/regex/regex.htm
原文:http://www.cnblogs.com/magicpower/p/5118383.html