Could not parse the remainder: '{{variabile}}' from '{{variabile}}'

95 views
Skip to first unread message

luca72

unread,
Jan 8, 2014, 11:33:34 AM1/8/14
to django...@googlegroups.com
hello the views file is like:

def test(request):
   testo = ["a","b"] 
   titolo = 'test'
   variabile = 'one'
   return render_to_response('vini.html',{'testo':testo,'titolo':titolo, 'testo':testo,'variabile':variabile,})

the template is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{% block title %}{{titolo}}{% endblock %}</title>
</head>
<body>
<div id="titoli">
{% block titoli %} {% endblock %}
</div>
<div id="navcontainer">
 <ul id="navlist">
 {% if {{variabile}} == "one" %}
 <li id="active"><a href="/mostro_prima" id="current">History</a></li>
 <li><a href="/vini">Wines</a></li>
 <li><a href="#">Foods</a></li>
 {% elif {{variabile}} == "two" %}
 <li><a href="/mostro_prima">History</a></li>
 <li id="active"><a href="/vini" id="current">Wines</a></li>
 <li><a href="#">Foods</a></li>
 {% else %}
 <li><a href="/mostro_prima">History</a></li>
 <li><a href="/vini">Wines</a></li>
 <li id="active"><a href="#" id="current">Foods</a></li>
 {% endif %}
 </ul>
</div> 
<div id="main">
{% block main %}{% for n in testo %}<br/>{{n}}{% endfor %}
<br/><br/><br/>
Contact : <br/>
Tel: +xxxxxxxxxx </br>
Mobile: +xxxxxxxxx2<br/>
Email : <a href="xxxxxxxxxxxxxxxxxxxxxxx"> info@xxxxxxxxxxxxxxxxxm</a> 
{% endblock %}
</div>
<div id= "immagini">
</div>
</body>
</html>

Why i get the error how i can solve?

Thanks

Luca

Jonathan Baker

unread,
Jan 8, 2014, 11:38:01 AM1/8/14
to django...@googlegroups.com
When referencing a context variable within an if statement in a template, you don't need to use {{ var }}. Simply use: {% if variabile == "one" %}...{% elif variable == "two" %}...{% else %}...{% endif %}.

JDB


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f9137164-20c7-4ab1-bb43-4062c267b03a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

Larry Martell

unread,
Jan 8, 2014, 11:39:26 AM1/8/14
to django...@googlegroups.com
On Wed, Jan 8, 2014 at 9:33 AM, luca72 <luca...@libero.it> wrote:
You do not need the {{ }} around context variables when they
referenced inside a template tag. Change

{% if {{variabile}} == "one" %}

to:

{% if variabile == "one" %}

and do the same for the elif.
Reply all
Reply to author
Forward
0 new messages