Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:27:40+00:00 2026-06-02T20:27:40+00:00

I am spitting out some values with a for loop and want to make

  • 0

I am spitting out some values with a for loop and want to make sure that it only displays X characters. I’m relatively new to Django.

For example:

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

Would produce a list of book authors, e.g.:

by Lennart Berggren & Jonathan M. Borwein & Peter B. Borwein

and I’d only like 30 characters, since sometimes the list of authors can be long.

I understand that I can use truncatechars (new in Django 1.4) to do this on a single value like {{author|truncatechars:9}}, but I’m wondering if there is an elegant way to apply to the for loop, or the resulting text from the for loop. Please let me know if this isn’t clear.

EDIT

truncatechars does not seem to work properly when used in a {% filter %}. All it produces is “…”. I’ll test some more, could be a bug. truncatewords works well, and I may be more suitable for this situation anyhow.

      <div class="bookauthor">
        by 
        {% filter truncatechars:30 %}
          {% for author in book.volumeInfo.authors %}
          {% if not forloop.first %}&amp;{% endif %}
            {{author}}
          {% endfor %}  
        {% endfilter %}  
     </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:27:43+00:00Added an answer on June 2, 2026 at 8:27 pm

    {% filter %}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a way that we are currently spitting out some HTML to our
I have some PHP code which runs a loop, spitting out a button and
I have some code that's working, but spitting out a lot of warnings. foreach
I'm debugging an app that is spitting out a huge amount of output that
I am working on splitting out an existing, working application that I currently have
I just figured this out but instead of splitting my new question (why?) into
Not sure how else to put that, but I'll start off with a code
I have a simple Sinatra app that I am playing with, and for some
I have some strings, entered by users, that may look like this: ++7 7++
I'm trying to make a WCF service that will work with JSON-P (long-story short,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.