2016-08-12 33 views
0

我有一個除了主頁路徑和我的博客頁面路徑以外的每個頁面都有一個標題,但是我似乎無法獲得'或'語句工作。任何想法都表示讚賞。謝謝。在Django的request.path {if}語句中包含多個路徑

這工作

{% if request.path != '/' %} 
... 
{% endif %} 

這不,但我需要什麼

{% if request.path != '/' or request.path != '/news' %} 
... 
{% endif %} 

回答

3

條件request.path != '/' or request.path != '/news'將始終返回true(request.path總是從一種或另一種不同值)。你需要在你的情況下使用and

{% if request.path != '/' and request.path != '/news' %} 
... 
{% endif %} 
+0

它總是簡單的事情,我忽略 - 謝謝。爲了獲得新聞路徑和帖子路徑本身,即/ news/post-url-path,我將它寫爲'{%if request.path!='/'和'/ news'not in request.path%}。 。{%endif%}' –