[Django] #12177: Error in part 4 of the tutorial?

View: New views
2 Messages — Rating Filter:   Alert me  

[Django] #12177: Error in part 4 of the tutorial?

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#12177: Error in part 4 of the tutorial?
---------------------------+------------------------------------------------
 Reporter:  simon_k        |       Owner:  nobody    
   Status:  new            |   Milestone:            
Component:  Documentation  |     Version:  1.1      
 Keywords:                 |       Stage:  Unreviewed
Has_patch:  0              |  
---------------------------+------------------------------------------------
 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
   92.                 response = callback(request, *callback_args,
 **callback_kwargs)
 File "d:\temp\django1\mysite\..\mysite\polls\views.py" in vote
   50.         }, context_instance=RequestContext(request))
 File "C:\python26\Lib\site-packages\django\shortcuts\__init__.py" in
 render_to_response
   20.     return HttpResponse(loader.render_to_string(*args, **kwargs),
 **httpresponse_kwargs)
 File "C:\python26\Lib\site-packages\django\template\loader.py" in
 render_to_string
   103.         t = get_template(template_name)
 File "C:\python26\Lib\site-packages\django\template\loader.py" in
 get_template
   82.     template = get_template_from_string(source, origin,
 template_name)
 File "C:\python26\Lib\site-packages\django\template\loader.py" in
 get_template_from_string
   90.     return Template(source, origin, name)
 File "C:\python26\lib\site-packages\django\template\__init__.py" in
 __init__
   168.         self.nodelist = compile_string(template_string, origin)
 File "C:\python26\lib\site-packages\django\template\__init__.py" in
 compile_string
   189.     return parser.parse()
 File "C:\python26\lib\site-packages\django\template\__init__.py" in parse
   283.                     self.invalid_block_tag(token, command)
 File "C:\python26\lib\site-packages\django\template\__init__.py" in
 invalid_block_tag
   335.         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

--
Ticket URL: <http://code.djangoproject.com/ticket/12177>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django updates" group.
To post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: [Django] #12177: Error in part 4 of the tutorial?

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
          Reporter:  simon_k        |         Owner:  nobody
            Status:  closed         |     Milestone:        
         Component:  Documentation  |       Version:  1.1  
        Resolution:  duplicate      |      Keywords:        
             Stage:  Unreviewed     |     Has_patch:  0    
        Needs_docs:  0              |   Needs_tests:  0    
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Changes (by kmtracey):

  * status:  new => closed
  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0
  * resolution:  => duplicate

Old 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
>   92.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "d:\temp\django1\mysite\..\mysite\polls\views.py" in vote
>   50.         }, context_instance=RequestContext(request))
> File "C:\python26\Lib\site-packages\django\shortcuts\__init__.py" in
> render_to_response
>   20.     return HttpResponse(loader.render_to_string(*args, **kwargs),
> **httpresponse_kwargs)
> File "C:\python26\Lib\site-packages\django\template\loader.py" in
> render_to_string
>   103.         t = get_template(template_name)
> File "C:\python26\Lib\site-packages\django\template\loader.py" in
> get_template
>   82.     template = get_template_from_string(source, origin,
> template_name)
> File "C:\python26\Lib\site-packages\django\template\loader.py" in
> get_template_from_string
>   90.     return Template(source, origin, name)
> File "C:\python26\lib\site-packages\django\template\__init__.py" in
> __init__
>   168.         self.nodelist = compile_string(template_string, origin)
> File "C:\python26\lib\site-packages\django\template\__init__.py" in
> compile_string
>   189.     return parser.parse()
> File "C:\python26\lib\site-packages\django\template\__init__.py" in parse
>   283.                     self.invalid_block_tag(token, command)
> File "C:\python26\lib\site-packages\django\template\__init__.py" in
> invalid_block_tag
>   335.         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

New 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
   92.                 response = callback(request, *callback_args,
 **callback_kwargs)
 File "d:\temp\django1\mysite\..\mysite\polls\views.py" in vote
   50.         }, context_instance=RequestContext(request))
 File "C:\python26\Lib\site-packages\django\shortcuts\__init__.py" in
 render_to_response
   20.     return HttpResponse(loader.render_to_string(*args, **kwargs),
 **httpresponse_kwargs)
 File "C:\python26\Lib\site-packages\django\template\loader.py" in
 render_to_string
   103.         t = get_template(template_name)
 File "C:\python26\Lib\site-packages\django\template\loader.py" in
 get_template
   82.     template = get_template_from_string(source, origin,
 template_name)
 File "C:\python26\Lib\site-packages\django\template\loader.py" in
 get_template_from_string
   90.     return Template(source, origin, name)
 File "C:\python26\lib\site-packages\django\template\__init__.py" in
 __init__
   168.         self.nodelist = compile_string(template_string, origin)
 File "C:\python26\lib\site-packages\django\template\__init__.py" in
 compile_string
   189.     return parser.parse()
 File "C:\python26\lib\site-packages\django\template\__init__.py" in parse
   283.                     self.invalid_block_tag(token, command)
 File "C:\python26\lib\site-packages\django\template\__init__.py" in
 invalid_block_tag
   335.         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

Comment:

 (Reformatted description, please use the preview button and
 WikiFormatting.)

 The problem is you are using the latest-development-level docs with a
 released level of the code, which does not have some of the recent changes
 introduced in trunk.  Specifically, csrf_token does not exist in 1.1.1 or
 earlier.  You can fix the problem you see by just deleting it from your
 template.

 The 1.1 level of the tutorial part 4 is here:
 http://docs.djangoproject.com/en/1.1/intro/tutorial04/#intro-tutorial04

 (The problem of there being no link to the 1.1.1 docs is covered by
 #12155.)

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django updates" group.
To post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---