问题
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?
回答1:
If you really want to shoot yourself in the foot:
Custom django filter that does that:
{% load replace %} {{ mystring|replace:"/l(u+)pin/m\1gen" }}
来源:https://stackoverflow.com/questions/12582715/using-regular-expression-in-django-templates