Reputation: 61
I'm having issue while configuring views and I am following django 1.5 official tutorial. Here is my Code for 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'),
)
Below is my polls/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)
In polls/urls.py I've also tried url(r'^(?P\d+)/detail/$', views.detail, name='detail'), instead of url(r'^(?P\d+)/$', views.detail, name='detail'), Error I'm getting is
File "C:\Python27\Scripts\mysite\polls\urls.py", line 7 url(r'^(?P\d+)/$', views.detail, name='detail'), ^ SyntaxError: invalid syntax [31/Dec/2013 06:06:34] "GET /admin/ HTTP/1.1" 500 84890
Please help.
Upvotes: 1
Views: 3564
Reputation: 12931
In your code
url(r'^(?P<poll_id>\d+/vote/$', views.vote, name='vote'),
should be
url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'),
You missed the parentness and you missed a comma after url(r'^$', views.index, name='index')
.
Upvotes: 2