I'm completely around the axle on this.
---------------------------------------------------------------------
** The log:
[26/May/2009 00:06:43] "GET /polls/1/detail/ HTTP/1.1" 200 333
[26/May/2009 00:06:49] "POST /polls/1/detail/vote/ HTTP/1.1" 404 2314
** The 404:
Using the URLconf defined in mysite.urls, Django tried these URL
patterns, in this order:
1. ^admin/
2. ^admin/doc/
3. ^polls/ ^admin/doc/
4. ^polls/ ^$
5. ^polls/ ^(?P<poll_id>\d+)/detail/$
6. ^polls/ ^(?P<poll_id>\d+)/results/$
7. ^polls/ ^(?P<poll_id>\d+)/vote/$
The current URL, polls/1/detail/vote/, didn't match any of these.
** The template (detail.html)
<h1>{{ poll.question }}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{%
endif %}
<form action="vote/" method="post">
{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}"
value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice }}</
label><br />
{% endfor %}
<input type="submit" value="Vote" />
</form>
** The Vote and Detail functions
from django.shortcuts import get_object_or_404, render_to_response
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from mysite.polls.models import Choice, Poll
def detail(request, poll_id):
try:
p = Poll.objects.get(pk=poll_id)
except Poll.DoesNotExist:
raise Http404
return render_to_response('polls/detail.html', {'poll': p,})
def vote(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the poll voting form.
return render_to_response('polls/detail.html', {
'poll': p,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully
dealing
# with POST data. This prevents data from being posted twice
if a
# user hits the Back button.
------------------------------------------------------------------------------------
When the Vote button is clicked, the URL is instantly appended with /
vote and (naturally) the 404 is raised.
This is my first trip with Django and little Python so I'm still
chasing the easy stuff. Sorry for the bother and thanks for taking the
time.
Allan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---