与此问题类似:
Django template, if tag based on current URL value
我只想检查网址中是否有单词-您知道,就像
if a.find(b) == -1
我怎样才能做到这一点?
最佳答案
{% if b in request.path %}
hello world!
{% endif %}
如果那不能满足您的需求,则将逻辑移至 View 或创建一个custom template tag.
关于django检查模板中的当前URL是否包含特定单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12877491/