django模板,找到字符串替换为其他字符串 [英] django templates, find string replace with other string
本文介绍了django模板,找到字符串替换为其他字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想把
转换成_ p> {{user.name}}
从我的名字到My_Name。我该怎么做?
解决方案
没有内置的标签或过滤器来做这个替换。编写一个由给定字符分割的过滤器,然后将其与 join
过滤器组合,或者写入直接进行替换的过滤器。
Hay, I'm writing some templates but I want to convert " " into "_" within a string.
I want to convert the output of
{{ user.name }}
from something like "My Name" to "My_Name". How do I do this?
解决方案
There is no built-in tag or filter to do this replacement. Write a filter that splits by a given character, and then combine that with the join
filter, or write a filter that does the replacement directly.
这篇关于django模板,找到字符串替换为其他字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文