模板过滤器来修剪任何前导或尾随空格 [英] template filter to trim any leading or trailing whitespace
本文介绍了模板过滤器来修剪任何前导或尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在django中是否有一个模板过滤器,它会从输入文本中修剪任何前导或尾随空格。
像$ {{var .example | trim}}
解决方案
你可以自己去做
$ b $从django导入模板$ d
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b @ register.filter
@stringfilter
def trim(value):
return value.strip()
Is there a template filter in django that will trim any leading or trailing whitespace from the input text.
Something like, {{ var.example|trim }}
解决方案
You can do it yourself
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def trim(value):
return value.strip()
这篇关于模板过滤器来修剪任何前导或尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文