Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在django模板中实现正则表达式_Regex_Django_Django Templates - Fatal编程技术网

Regex 在django模板中实现正则表达式

Regex 在django模板中实现正则表达式,regex,django,django-templates,Regex,Django,Django Templates,我通过检查url是否与当前url匹配,使页面导航处于活动状态 <li> {% url 'blog' as blog_url %} <a href="{{blog_url}}" {% if request.get_full_path == blog_url %}class="active"{% endif %}>Blog</a> </li> 上面的代码不起作用。因此,在模板中使用regex是否可以获得像/blog/*这样的内容并使其处于活动

我通过检查url是否与当前url匹配,使页面导航处于活动状态

<li>
  {% url 'blog' as blog_url %}
  <a href="{{blog_url}}" {% if request.get_full_path == blog_url %}class="active"{% endif %}>Blog</a>
</li>
上面的代码不起作用。因此,在模板中使用regex是否可以获得像/blog/*这样的内容并使其处于活动状态。非常感谢您的帮助和指导。谢谢。

你可以这样做

{% if '/blog/' in request.path %}class="active"{% endif %}
不需要regexp

您只需

{% if '/blog/' in request.path %}class="active"{% endif %}
不需要regexp