【发布时间】:2014-01-18 11:14:46
【问题描述】:
我在配置视图时遇到问题,我正在关注 django 1.5 官方教程。 这是我的 polls/urls.py 代码。
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns ('',
url(r'^$', views.index, name='index')
url(r'^(?P<poll_id>\d+)/$', views.detail, name='detail'),
url(r'^(?P<poll_id>\d+)/results/$', views.results, name='reults'),
url(r'^(?P<poll_id>\d+/vote/$', views.vote, name='vote'),
)
下面是我的投票/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the poll index.")
def detail(request, poll_id):
return HttpResponse("You’re looking at poll %s." % poll_id)
def results(request, poll_id):
return HttpResponse("You’re looking at the results of poll %s." % poll_id)
def vote(request, poll_id):
return HttpResponse("You’re voting on poll %s." % poll_id)
在 polls/urls.py 我也试过 url(r'^(?P\d+)/detail/$', views.detail, name='detail'), 代替 url(r'^(?P\d+)/$', views.detail, name='detail'), 我得到的错误是
文件“C:\Python27\Scripts\mysite\polls\urls.py”,第 7 行 url(r'^(?P\d+)/$', views.detail, name='detail'), ^ SyntaxError:无效的语法 [2013 年 12 月 31 日 06:06:34] "GET /admin/ HTTP/1.1" 500 84890
请帮忙。
【问题讨论】: