how to split the string in django template?

前端 未结 3 1684
轻奢々
轻奢々 2020-12-10 05:17

i am trying to split the string in template using custom template filter. But i got an error

    TemplateSyntaxError at /job/16/
\'for\' statements should u         


        
相关标签:
3条回答
  • 2020-12-10 05:58

    The direct for loop works too, you just have to remove the spaces in the syntax:

        <h4>Skills</h4>
                {% for skill in form.instance.skills|split:"," %}
                    {{ skill }}
                  {% endfor %}
    
    0 讨论(0)
  • 2020-12-10 06:13
    <h4>Skills</h4>
    {% with form.instance.skills|split:"," as skills %}
        {% for skill in skills %}
            {{ skill }}<br>
        {% endfor %}
    {% endwith %}
    
    0 讨论(0)
  • 2020-12-10 06:13

    For extract character string, use filter cut:

    <a href="tel://+1{{ phone|cut:'-' }}">Phone</a>
    

    this removes the scripts from the string.

    0 讨论(0)
提交回复
热议问题