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

1 view
Skip to first unread message

Django

unread,
Nov 6, 2009, 9:17:03 AM11/6/09
to djang...@holovaty.com, django-...@googlegroups.com
#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.

Django

unread,
Nov 6, 2009, 9:33:51 AM11/6/09
to djang...@holovaty.com, django-...@googlegroups.com
#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:
New description:
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

unread,
Jan 12, 2010, 12:39:10 AM1/12/10
to djang...@holovaty.com, django-...@googlegroups.com
#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
Reporter: simon_k | Owner: nobody
Status: reopened | Milestone:
Component: Documentation | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Changes (by datakid):

* status: closed => reopened
* version: 1.1 => SVN
* resolution: duplicate =>

Comment:

Hmm, this response is what I read about the traps, which is fine except
I'm using django-trunk - updated this morning:

{{{
musicman@brunswick:~/source/django-trunk$ svn info
Path: .
URL: http://code.djangoproject.com/svn/django/trunk
Repository Root: http://code.djangoproject.com/svn
Repository UUID: bcc190cf-cafb-0310-a4f2-bffc1f526a37
Revision: 12205
Node Kind: directory
Schedule: normal
Last Changed Author: zgoda
Last Changed Rev: 12205
Last Changed Date: 2010-01-11 20:25:10 +1100 (Mon, 11 Jan 2010)
}}}

Then I followed the
[http://docs.djangoproject.com/en/dev/ref/contrib/csrf/ dev instructions]
and am still getting errors, although they are new ones:

{{{
Traceback (most recent call last):

File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 279, in run
self.result = application(self.environ, self.start_response)

File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 651, in __call__
return self.application(environ, start_response)

File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py", line
230, in __call__
self.load_middleware()

File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line
46, in load_middleware
raise exceptions.ImproperlyConfigured, 'Middleware module "%s" does
not define a "%s" class' % (mw_module, mw_classname)

ImproperlyConfigured: Middleware module "django.contrib.csrf" does not
define a "CsrfViewMiddleware" class
}}}

From the dev instructions I've taken the new MIDDLEWARE_CLASS
'django.middleware.csrf.CsrfViewMiddleware' but otherwise have followed
tutorial instructions (ie, I'm using the RequestContext section of part 3
in teh csrf instructions...)

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:2>

Django

unread,
Jan 12, 2010, 8:52:07 AM1/12/10
to djang...@holovaty.com, django-...@googlegroups.com
#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
Reporter: simon_k | Owner: nobody
Status: closed | Milestone:
Component: Documentation | Version: SVN
Resolution: duplicate | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Changes (by russellm):

* status: reopened => closed
* resolution: => duplicate

Comment:

It sounds like you're not following the tutorial exactly. If you're
following the tutorial, you shouldn't need to delve into the CSRF
documention at all - you should only need to follow the steps that the
tutorial gives you. Also, django.middleware.csrf.CsrfViewMiddleware
clearly does exist in trunk, as does the csrf_token template tag.

I don't know exactly what is going wrong with your particular setup; until
we know there is a specific problem with the tutorial, this isn't
something that should be in Trac. Please follow this up on Django-users
and explain exactly what you have done; if it turns out that there is a
problem with the tutorial, we can open a new ticket.

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:3>

Django

unread,
Jan 13, 2010, 2:33:08 AM1/13/10
to djang...@holovaty.com, django-...@googlegroups.com
#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
Reporter: simon_k | Owner: nobody
Status: closed | Milestone:
Component: Documentation | Version: SVN
Resolution: duplicate | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Comment (by datakid):

fwiw, the tutorial _doesn't_ work. Feel free to test yourself. I have been
advised by #django irc to move back to stable.

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:4>

Django

unread,
Jan 13, 2010, 2:36:55 AM1/13/10
to djang...@holovaty.com, django-...@googlegroups.com
#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
Reporter: simon_k | Owner: nobody
Status: closed | Milestone:
Component: Documentation | Version: SVN
Resolution: duplicate | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Comment (by datakid):

I apologise for being a pedant - please ignore this last comment.

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:5>

Django

unread,
Jan 13, 2010, 5:38:11 AM1/13/10
to djang...@holovaty.com, django-...@googlegroups.com
#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
Reporter: simon_k | Owner: nobody
Status: closed | Milestone:
Component: Documentation | Version: SVN
Resolution: duplicate | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Comment (by lukeplant):

In case you didn't find your problem yet, I notice that the directory that
contains your SVN checkout (~/source/django-trunk) does not appear in your
tracebacks (which contain /usr/lib/pymodules/python2.6/django/...). This
indicates that your SVN checkout is not being used i.e. it's not at an
appropriate place on your PYTHONPATH. I recommend virtualenv for sorting
this kind of thing out.

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:6>

Django

unread,
Nov 5, 2010, 3:08:56 AM11/5/10
to djang...@holovaty.com, django-...@googlegroups.com
#12177: Error in part 4 of the tutorial?
------------------------------------+---------------------------------------
Reporter: simon_k | Owner: nobody
Status: closed | Milestone:
Component: Documentation | Version: SVN
Resolution: duplicate | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Comment (by chictimberland):

The good <A href="http://www.timberland-6inch.co.uk/">timberland 6 inch
boots</A> news is that you can stop the cycle before it gets bad. When you
start to notice signs of <A href="http://www.timberland-6inch.co.uk
/Timberland-Mens-6-Inch-Premium-Boots.html">timberland 6 inch premium
boot</A> tension, talk to your partner. This may seem like the last <A
href="http://www.timberland-6inch.co.uk/Timberland-Womens-14-Inch-Premium-
Boots.html">timberland 14 inch premium boots</A> thing in the world you
want to do, but this five-minute talk can be the difference between you
ending <A href="http://www.timberland-6inch.co.uk/Timberland-Womens-14
-Inch-Premium-Boots.html">womens 14 inch boots</A> up in an unhealthy
relationship or keeping <A href="http://www.timberland-6inch.co.uk
/Timberland-Womens-Roll-Top-Boots.html">womens timberland roll top
boots</A> safe. Within the conversation call them on what they’ve been
doing <A href="http://www.timberland-6inch.co.uk/Timberland-Mens-Roll-Top-
Boots.html">timberland roll top boots</A> and let them know it’s not okay.
Be clear that you will end things if this <A href="http://www.timberland-
6inch.co.uk/Timerland-Mens-Nellie-Chukka-Boots.html">timberland chukka
boots</A> behavior continues. Watch how your partner reacts. If they blow
it off, it’s time to get out; chances are if you stay in the <A
href="http://www.timberland-6inch.co.uk/Timerland-Mens-Nellie-Chukka-
Boots.html">timberland chukka boots for men</A> relationship the abuse
will continue and possibly worsen. If your partner seems serious about
making the <A href="http://www.timberland-6inch.co.uk/Timberland-Kids-
Premium-Waterproof-Boots.html">kids timberland boots</A> changes and
understands where you’re coming from, he can earn a second chance. But
abusers don’t usually just do it once, so create a <A href="http://www
.timberland-6inch.co.uk/Timberland-Classic-3-Eye-Handsewn-
Shoes.html">timberland boat shoes</A> plan of action in case the abuse
continues. This plan should include things like who you can call and where
you can go to get out of a bad <A href="http://www.timberland-6inch.co.uk
/Timberland-Classic-3-Eye-Handsewn-Shoes.html">timberland boat shoes
sale</A> situation. No matter how far into the cycle you are, it is
possible to leave. First talk to someone. Develop a safety <A
href="http://www.timberland-6inch.co.uk/">timberland boots</A> plan, and
then break things off. Once apart, avoid getting sucked back into the
relationship by distancing yourself as far as possible from them and
asking others to watch out for you. Do anything and everything to keep
yourself <A href="http://www.timberland-6inch.co.uk/">timberland boot
company</A> safe.

--
Ticket URL: <http://code.djangoproject.com/ticket/12177#comment:7>
Reply all
Reply to author
Forward
0 new messages