Using regular expression in Django templates

怎甘沉沦 提交于 2019-12-07 12:12:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!