{% elif %} error

1,590 views
Skip to first unread message

Tsung-Hsien

unread,
Dec 28, 2011, 1:44:58 AM12/28/11
to Django users
Hi,
I want to use {% elif %}
my template:
{% if bookmark.hours %}
{{ bookmark.hours }} hours ago
{% elif bookmark.days %}
{{ bookmark.days }} days ago
{% elif bookmark.months %}
{{ bookmark.months }} months ago
{% else %}
{{ bookmark.years }} years ago
{% endif %}


show error:
Invalid block tag: 'elif', expected 'else' or 'endif'

It can work without elif, if use if...else loop.

my django version is 1.31

how to solve this?
thanks!!



Russell Keith-Magee

unread,
Dec 28, 2011, 1:50:25 AM12/28/11
to django...@googlegroups.com

The {% elif %} tag was only recently added to Django; it will be
available in the 1.4 release. Django 1.3 and earlier does not, and
will not ever contain the {% elif %} tag.

You can either develop your site against Django's trunk in the hope
that Django will release 1.4 before you need to roll out your site, or
modify your template to use nested {% if %} statements.

Yours,
Russ Magee %-)

Donald Stufft

unread,
Dec 28, 2011, 1:51:53 AM12/28/11
to django...@googlegroups.com
Or back port the elif tag (which may or may not be non trivial).
--
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.

Nikhil Verma

unread,
Dec 28, 2011, 1:54:50 AM12/28/11
to django...@googlegroups.com
Hi

It is available in dev/trunl version not this version.

This is  dev version  docs
https://docs.djangoproject.com/en/dev/ref/templates/builtins/

--
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.




--
Regards
Nikhil Verma
+91-958-273-3156

yati sagade

unread,
Dec 28, 2011, 1:55:23 AM12/28/11
to django...@googlegroups.com
There's no {% elif %}. You'll have to do:


{% if bookmark.hours %}
{{bookmark.hours}} hours ago
{% else %}
   {% if bookmark.days %}
   {{ bookmark.days }} days ago
   {% else %}
      {% if bookmark.months %}

      {{ bookmark.months }} months ago
      {% else %}
       {{ bookmark.years }} years ago
      {% endif %}
   {% endif %}
 {%endif}

(Sorry if I missed any closing {%endif%} - you'll have to balance those). Also, I'd suggest you to do this logic part in the view itself.

Tsung-Hsien

unread,
Dec 28, 2011, 2:08:23 AM12/28/11
to Django users
Thank you all!

I don't see the line
"New in Django Development version."

Nikhil Verma

unread,
Dec 28, 2011, 2:13:37 AM12/28/11
to django...@googlegroups.com
Go to this link

https://docs.djangoproject.com/en/dev/ref/templates/builtins/

{% if athlete_list %}
Number of athletes: {{ athlete_list|length }}
{% elif athlete_in_locker_room_list %}
Athletes should be out of the locker room soon!
{% else %}
No athletes.
{% endif %}

press CLTR + F and type elif you will reach there




--
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.

Mário Neto

unread,
Dec 28, 2011, 6:47:15 AM12/28/11
to django...@googlegroups.com
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#firstof 

2011/12/28 Nikhil Verma <varma.n...@gmail.com>



--
Att. Mário A. Chaves Neto
Programmer, Designer and U.I. Engineer
MBA - Design Digital

Reply all
Reply to author
Forward
0 new messages