Make sure that you have the CSRF middleware installed. On Nov 3, 2009 12:09 PM, "Todd Blanchard" <tblanch...@mac.com> wrote:
What did I screw up? TemplateSyntaxError at /polls/1/ Invalid block tag: 'csrf_token' Request Method:GETRequest URL:http://localhost:8000/polls/1/Exception Type: TemplateSyntaxErrorException Value: Invalid block tag: 'csrf_token' Exception Location:/Library/Python/2.6/site-packages/django/template/__init__.py in invalid_block_tag, line 335Python Executable:/usr/bin/pythonPython Version:2.6.1 The forms bit. views.py: # Create your views here. from django.template import Context, loader from mysite.polls.models import Choice, Poll from django.http import HttpResponse from django.shortcuts import render_to_response, get_object_or_404 from django.http import Http404 from django.template import RequestContext # ... def index(request): latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5] return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list}) def detail(request, poll_id): p = get_object_or_404(Poll, pk=poll_id) return render_to_response('polls/detail.html', {'poll': p}, context_instance=RequestContext(request)) def results(request, poll_id): return HttpResponse("You're looking at the results of poll %s." % poll_id) 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('mysite.polls.views.results', args=(p.id,))) detail.html: <h1>{{ poll.question }}</h1> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} <form action="/polls/{{ poll.id }}/vote/" method="post"> {% csrf_token %} {% 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> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---