Newbie Stuck on Django Tutorial 3 - Django Template system

139 views
Skip to first unread message

Bob Loblaw

unread,
May 17, 2012, 2:39:53 PM5/17/12
to Django users
I was cruising along fine, but am stuck now... Any help would be
greatly appreciated

OS: Mac OS X Version 10.6.8
Python: 2.6.1
Django: 1.4

Issue: system throwing an error message during template rendering when
trying to implement Django template system. So I guess I must have a
config snag somewhere in Django.



Here is the error message...

Error during template rendering

In template /data/templates/polls/index.html, error at line 20
Invalid block tag: '</b></span><span'
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier;
color: #008080; background-color: #e0ffb8}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier;
background-color: #e0ffb8}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier;
color: #000080; background-color: #e0ffb8}
13 span.s1 {color: #999999}
14 span.s2 {color: #000000}
15 span.s3 {color: #000080}
16 span.s4 {color: #bb8844}
17 </style>
18 </head>
19 <body>
20 <p class="p1"><span class="s1"><b>{%</b></span><span class="s2">
<b>if</b> </span>latest_poll_list<span class="s2"> </span><span
class="s1"><b>%}</b></span></p>
21 <p class="p2"><span class="Apple-converted-space"> </span><span
class="s3">&lt;ul&gt;</span></p>
22 <p class="p1"><span class="s2"><span class="Apple-converted-
space"> </span></span><span class="s1"><b>{%</b></span><span
class="s2"> <b>for</b> </span>poll<span class="s2"> <b>in</b> </
span>latest_poll_list<span class="s2"> </span><span class="s1"><b>%}</
b></span></p>
23 <p class="p1"><span class="s2"><span class="Apple-converted-
space"> </span></span><span class="s3">&lt;li&gt;&lt;a</
span><span class="s2"> </span>href=<span class="s4">"/polls/</
span><span class="s1"><b>{{</b></span><span class="s2"> </
span>poll.id<span class="s2"> </span><span class="s1"><b>}}</b></
span><span class="s4">/"</span><span class="s3">&gt;</span><span
class="s1"><b>{{</b></span><span class="s2"> </span>poll.question<span
class="s2"> </span><span class="s1"><b>}}</b></span><span
class="s3">&lt;/a&gt;&lt;/li&gt;</span></p>
24 <p class="p2"><span class="Apple-converted-space"> </span><span
class="s1"><b>{%</b></span> <b>endfor</b> <span class="s1"><b>%}</b></
span></p>
25 <p class="p3"><span class="s2"><span class="Apple-converted-
space"> </span></span>&lt;/ul&gt;</p>
26 <p class="p2"><span class="s1"><b>{%</b></span> <b>else</b> <span
class="s1"><b>%}</b></span></p>
27 <p class="p2"><span class="Apple-converted-space"> </span><span
class="s3">&lt;p&gt;</span>No polls are available.<span
class="s3">&lt;/p&gt;</span></p>
28 <p class="p2"><span class="s1"><b>{%</b></span> <b>endif</b> <span
class="s1"><b>%}</b></span></p>
29 </body>
30 </html>


Here is the index.html (verbatim from tutorial)...

{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></
li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}

Marcin Tustin

unread,
May 17, 2012, 2:54:00 PM5/17/12
to django...@googlegroups.com
This is your problem:  {%</b></span> <b>else</b> <span
class="s1"><b>%} 

Everything between {% and %} is interpreted as template-syntax code. 


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




--
Marcin Tustin
Tel: 07773 787 105

Daniel Roseman

unread,
May 17, 2012, 4:18:51 PM5/17/12
to django...@googlegroups.com
That's not the template file that's being used, as you can see from the error traceback - the real file appears to have a whole load of extraneous formatting in it. Are you using something like Word to edit your templates?
--
DR.

Chou Sunny

unread,
Jul 28, 2014, 8:49:13 PM7/28/14
to django...@googlegroups.com

i had the same problem by just copying the text on the web, pasting on textedit, and saving it into html.
when i open html by Xcode, you will see extra lines, more than the text on the web.
simply re-edit html by Xcode, the problem is solved.
Reply all
Reply to author
Forward
0 new messages