Opened 14 years ago

Last modified 10 years ago

#12177 closed

Error in part 4 of the tutorial? — at Initial Version

Reported by: simon_k Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am pretty sure I was following *exactly*

tutorial url: http://docs.djangoproject.com/en/dev/intro/tutorial04/#intro-tutorial04

The (apparent) error in code shown at the top of the page (the template for the "simple form")


Start of output resulting response from dev server:


Environment:

Request Method: GET
Request URL: http://localhost:8000/polls/2/vote/
Django Version: 1.1.1
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls',
'django.contrib.admin']

Installed Middleware:
('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')

Template error:
In template d:\temp\django1\mysite\polls\templates\polls\detail.html, error at line 6

Invalid block tag: 'csrf_token'
1 : <h1>{{ poll.question }}</h1>

2 :

3 : {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

4 :

5 : <form action="/polls/{{ poll.id }}/vote/" method="post">

6 : {% csrf_token %}

7 : {% for choice in poll.choice_set.all %}

8 : <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />

9 : <label for="choice{{ forloop.counter }}">{{ choice.choice }}</label><br />

10 : {% endfor %}

11 : <input type="submit" value="Vote" />

12 : </form>

13 :

Traceback:
File "C:\python26\Lib\site-packages\django\core\handlers\base.py" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "d:\temp\django1\mysite\..\mysite\polls\views.py" in vote

  1. }, context_instance=RequestContext(request))

File "C:\python26\Lib\site-packages\django\shortcuts\init.py" in render_to_response

  1. return HttpResponse(loader.render_to_string(*args, kwargs), httpresponse_kwargs)

File "C:\python26\Lib\site-packages\django\template\loader.py" in render_to_string

  1. t = get_template(template_name)

File "C:\python26\Lib\site-packages\django\template\loader.py" in get_template

  1. template = get_template_from_string(source, origin, template_name)

File "C:\python26\Lib\site-packages\django\template\loader.py" in get_template_from_string

  1. return Template(source, origin, name)

File "C:\python26\lib\site-packages\django\template\init.py" in init

  1. self.nodelist = compile_string(template_string, origin)

File "C:\python26\lib\site-packages\django\template\init.py" in compile_string

  1. return parser.parse()

File "C:\python26\lib\site-packages\django\template\init.py" in parse

  1. self.invalid_block_tag(token, command)

File "C:\python26\lib\site-packages\django\template\init.py" in invalid_block_tag

  1. raise self.error(token, "Invalid block tag: '%s'" % command)

Exception Type: TemplateSyntaxError at /polls/2/vote/
Exception Value: Invalid block tag: 'csrf_token'


End of output resulting response from dev server:


... by the way nice tutorial!

Regards,
Simon

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top