在Django模板中使用正则表达式 [英] Using regular expression in Django templates
本文介绍了在Django模板中使用正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以在Django模板中使用正则表达式:
I wonder if it is possible using regular expression in Django templates:
<a href="#{{form.deal_template_name.value}} ????" data-toggle="tab">{{form.deal_template_name.value}}</a>
我想用_代替空格和点号。 (否则,链接将对目标造成麻烦)
I would like to replace both spaces and dot's with _. (Otherwise the link would have trouble with the target)
{{form.deal_template_name.value}}
.replace(/ /g,"_").replace(/\./g,"_")
虽然可以直接在模板中执行此操作吗?
How to do that though in template directly, is that possible?
推荐答案
如果您真的想拍摄自己站起来:
If you really want to shoot yourself in the foot:
自定义Django过滤器就是这样:
{% load replace %} {{ mystring|replace:"/l(u+)pin/m\1gen" }}
这篇关于在Django模板中使用正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文