Akh*_*khi 6 django-templates django-filter django-1.5
我试图使用自定义模板过滤器在模板中拆分字符串.但是我得到了一个错误
TemplateSyntaxError at /job/16/
'for' statements should use the format 'for x in y': for skill in form.instance.skills | split : ","
Run Code Online (Sandbox Code Playgroud)
这是我的过滤器
@register.filter(name='split')
def split(value, key):
"""
Returns the value turned into a list.
"""
return value.split(key)
Run Code Online (Sandbox Code Playgroud)
这是我的模板
<h4>Skills</h4>
{% for skill in form.instance.skills | split : "," %}
{{ skill }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
谢谢
<h4>Skills</h4>
{% with form.instance.skills|split:"," as skills %}
{% for skill in skills %}
{{ skill }}<br>
{% endfor %}
{% endwith %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8698 次 |
| 最近记录: |