如果当前url中有特定的单词,则django在模板中检查

时间:2012-10-13 22:12:10

标签: django

与此问题类似:

Django template, if tag based on current URL value

只有我想检查网址中是否有单词 - 你知道,比如

if a.find(b) == -1

我该怎么做?

2 个答案:

答案 0 :(得分:9)

Perhaps the in operator?

{% if b in request.path %}
    hello world!
{% endif %}

如果这不能满足您的需求,请将逻辑移至您的视图或创建custom template tag.

答案 1 :(得分:0)

忘记request参数并使用:

{% if 'search_term' in request.GET %}
  Hello World!
{% endif %}