Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
类似于这个问题:
Django 模板,if 标记基于当前 URL 值
只有我想检查 url 中是否有单词 - 你知道,比如
if a.find(b) == -1
我怎样才能做到这一点?
也许是in运营商?
in
{% if b in request.path %} hello world! {% endif %}
如果这不能满足您的需要,则将逻辑移动到您的视图或创建自定义模板标签。
忘记request参数并使用:
request
{% if 'search_term' in request.GET %} Hello World! {% endif %}