2016-08-12 32 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%}' –