doniyor
doniyor

Reputation: 37904

django - how to make newline in many if-clauses

I am wondering how I can make newline if I have many if-clauses like this:

{% if request.path != "/a/" and request.path != "/b/" and request.path != "/c/" ...many more %}

{% endif %}

I want to be able to do something like this:

{% if request.path != "/a/" 
   and request.path != "/b/" 
   and request.path != "/c/" 
   ...many more %}

{% endif %}

or something shorter.

Upvotes: 1

Views: 25

Answers (1)

alecxe
alecxe

Reputation: 474001

What if you put the list of paths into the context:

return render_to_response('mytemplate.html', {'paths': ['/a/', '/b/', '/c/']})

And use built-in in in the template:

{% if request.path in paths %}
    do something
{% endif %}

Upvotes: 1

Related Questions