1

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.

1 Answer 1

2

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').

Sign up to request clarification or add additional context in comments.

7 Comments

It is giving me same error...i've corrected it though. Seems like the problem is in views.vote URL configuration.
I am really sorry for inconvenience actually i've typed in the code again and again so that's why making small mistakes.
However its giving me again the error. File "C:\Python27\Scripts\mysite\polls\views.py", line 7 SyntaxError: Non-ASCII character '\xe2' in file C:\Python27\Scripts\mysite\polls \views.py on line 7, but no encoding declared; see python.org/peps/pe p-0263.html for details [31/Dec/2013 07:08:37] "GET /admin/ HTTP/1.1" 500 97589
Add # -*- coding: utf-8 -*- to the first line of views.
Tried it and its giving me error on that particular line where its added. Also tried a lot of solution up till now from last 3 hours.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.