urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^(?P<question_id>\d+)/$', views.detail, name='detail'),
url(r'^(?P<question_id>\d+)/results/$',views.results, name='results'),
url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext, loader
from polls.models import Question, Choice
from django.http import Http404
from django.core.urlresolvers import reverse
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = RequestContext(request, {'latest_question_list' : latest_question_list, })
return HttpResponse(template.render(context))
def detail(request, question_id):
try:
question = Question.objects.get(pk = question_id)
except Question.DoesNotExist:
raise Http404("Question ne postoji")
return render(request, 'polls/detail.html', {'question': question})
def results(request, question_id):
question = get_object_or_404(Question, pk = question_id)
return render(request, 'polls/results.html', {'guestion': question})
def vote(request, question_id):
p = get_object_or_404(Question, pk=question_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
return render(request, 'polls/detail.html', {
'question': p,
'error_message': "Nijesi izabrao pitanje.",
})
else:
selected_choice.votes += 1
selected_choice.save()
return HttpResponseRedirect(reverse('polls:results', args=(p.id,)))
I'm guessing the issue is actually in your template if you are following along that page. None of the code in your views would generate that error from what I can see.
The error indicates that you are trying to reverse('polls:detail') and not providing any arguments for the URL resolver (or are passing an empty/missing variable). In the template, this would probably look something like {% url 'polls:detail' %}. I would guess that you are forgetting question.id after the view name, assuming you are using the same variable names as the tutorial.
Check near the bottom of the stack trace on the page, I bet it has a {% url %} tag highlighted as the culprit.
-James
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2e2320f1-6813-4e01-8b32-76694dbd22f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
HM,
Upon a closer look at your code (views.results), you have this:
return render(request, 'polls/results.html', {'guestion': question})
You are passing "guestion" (with a G) to the template instead of "question" (with a Q).
As such, your template complains when you try to use "question.id" because it is expecting "guestion.id" (with a G).
Change it to {'question': question} (with a Q) in views.results and see how it goes again.
All the best. :)
Sincerely,
Muhammad
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%2B5VyP-vOtdWzW%2BCJj5kFG_XwOFYi-EJfb3Toq31fD%2BKEiGuw%40mail.gmail.com.
I agree that the typo is also an issue and should be fixed, but that wouldn't result in the OP's error, since reverse() is complaining about a 'detail' URL specifically. The typo would result in a similar error when the result page is displayed, and would show 'guestion' as one of the kwargs.
-James
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJOFuZwHryu87L4zHBfrd73g%3Di_kSZuo0FMfT9TkAdE051hHcA%40mail.gmail.com.
I agree that the typo is also an issue and should be fixed, but that wouldn't result in the OP's error, since reverse() is complaining about a 'detail' URL specifically. The typo would result in a similar error when the result page is displayed, and would show 'guestion' as one of the kwargs.
-James