django检查模板中的当前URL是否包含特定单词

标签 django

与此问题类似:

Django template, if tag based on current URL value

我只想检查网址中是否有单词-您知道,就像

if a.find(b) == -1

我怎样才能做到这一点?

最佳答案

Perhaps the in operator?

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

如果那不能满足您的需求,则将逻辑移至 View 或创建一个custom template tag.

关于django检查模板中的当前URL是否包含特定单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12877491/

相关文章:

django - 保存后不立即更新多对多关系的问题

ruby-on-rails - 等同于 Rails 的 Django 信号?

javascript - 如何在html和javascript中声明全局变量

python - 将当前 User 对象附加到 Django 表单

python - 索引聊天日志并在 Django 中搜索它们

html - Django 中模板标签的样式

python - 如何为mysql安装模块?

django - 类型错误 : Cannot create a consistent MRO for bases Mixin, 对象

mysql - Django 日期列表

python - 如何使用django中的函数显示另一个表中的值