B
B
Bulbashful2016-05-12 16:32:54
Django
Bulbashful, 2016-05-12 16:32:54

NoReverseMatch?

I'm doing a test following the example with djbook. There, the voting itself is implemented in a hotel application, I want to do everything in one. Without reverse() in HttpResponseRedirect everything works. How can I properly use the namespace in it?
url.py

url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'article.views.main',name="main"),
    url(r'^result/$', 'article.views.result', name="result"),
    url(r'^vote/$', 'article.views.vote', name="vote"),

view.py
def vote(request):
    p = get_object_or_404(Question,pk=1)
    try:
        selected_choice = p.choice_set.get(pk=request.POST['choice'])
    except (KeyError,Choice.DoesNotExist):
        return render(request,'main.html',{
            'question:':p,
            'error_message': "Вы не выбрали вариант ответа",
        })
    else:
        selected_choice.votes +=1
        selected_choice.save()
        return HttpResponseRedirect(reverse('article:result', args=[p.id,]))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Aksenov, 2016-05-12
@Bulbashful

For starters, you need to read more carefully. There is a description of polls/urls.py, compare with your urls.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question