如何在Django模板循环中截断文本

如何在Django模板循环中截断文本,django,django-templates,Django,Django Templates,我用for循环吐出一些值,并希望确保它只显示X个字符。我对Django比较陌生 例如: <div class="bookauthor"> by {% for author in book.volumeInfo.authors %} {% if not forloop.first %}&amp;{% endif %} {{author}} {% endfor %} </div> <di

我用for循环吐出一些值,并希望确保它只显示X个字符。我对Django比较陌生

例如:

  <div class="bookauthor">
    by 
    {% for author in book.volumeInfo.authors %}
      {% if not forloop.first %}&amp;{% endif %}
      {{author}}
    {% endfor %} 
  </div>

      <div class="bookauthor">
        by 
        {% filter truncatechars:30 %}
          {% for author in book.volumeInfo.authors %}
          {% if not forloop.first %}&amp;{% endif %}
            {{author}}
          {% endfor %}  
        {% endfilter %}  
     </div>