>From the tutorial of Django, there is the following code in 
>here<http://docs.djangoproject.com/en/1.2/intro/tutorial04/>

<http://docs.djangoproject.com/en/1.2/intro/tutorial04/>Who knows 
the mechanism behind a redirect or a direct response? Refer the comments 
below. Thanks a lot!

from django.shortcuts import get_object_or_404, render_to_responsefrom 
django.http import HttpResponseRedirect, HttpResponsefrom 
django.core.urlresolvers import reversefrom django.template import 
RequestContextfrom polls.models import Choice, Poll# ...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.",
        }, context_instance=RequestContext(request))
    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.*
        return HttpResponseRedirect(reverse('polls.views.results', 
args=(p.id,)))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to