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 6551495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:20:42+00:00 2026-05-25T12:20:42+00:00

I’m pretty new to Django’s template system- Basically, I’m trying to print out all

  • 0

I’m pretty new to Django’s template system-
Basically, I’m trying to print out all the contents of a list that I’m passing to django in a context.

The relevant part of my urls.py is here-

 url(r'^class/$', twobooks.classes.views.getAllInformation, {'template_name':'classes/displayBooks.html'}),

Now, in my views getAllInformation is as follows-

def getAllInformation(searchTerm,template_name):
    nameAndNumberStore = modifySearchTerm(searchTerm)
    url = modifyUrl(nameAndNumberStore)
    soup = getHtml(url)
    information = []
    if (checkIfValidClass(soup,nameAndNumberStore)):
        storeOfEditions = getEdition(soup)
        storeOfAuthorNames = getAuthorName(soup)
        storeOfBookNames = getBookNames(soup)
        storeOfImages = getImages(soup)
    information.append(storeOfAuthorNames)#REMEMBER this is a list of two lists 
    information.append(storeOfEditions)
    return render_to_response(
    template_name,
    {'authors': storeOfAuthorNames},
    )

and displayBooks.html is as follows-

<html>
<head>
<body>
<h1>Testing the class page backend</h1>
<ul>
{ % for author in authors|safe% }
    <li>{{ author }}</li>
{ % endfor % }
</ul>

</body> 

</html>

I think this is fairly simple, but I’m not sure what’s going on, so thought I’d ask for some help – thanks!

  • 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-05-25T12:20:43+00:00Added an answer on May 25, 2026 at 12:20 pm

    Applying the safe filter will turn anything into a string. If you start with the literal [1, 2, 'foo', u'bar'], you’re going to end up with approximately the literal u"[1, 2, 'foo', u'bar']" (or something like it—I’m not quite certain of how it’s rendered as I’ve never tried doing it; also I say “approximately” as it’s actually a SafeString instance not a unicode instance). Then, iteration is going over each character in the produced string, which isn’t what you want.

    Instead, you can use the safeseq filter which applies the safe filter to each element in the sequence,

    <ul>
    {% for author in authors|safeseq %}
        <li>{{ author }}</li>
    {% endfor %}
    </ul>
    

    Or, you could apply safe to the value inside the iterator.

    <ul>
    {% for author in authors %}
        <li>{{ author|safe }}</li>
    {% endfor %}
    </ul>
    

    I would recommend safeseq, as you may then be able to optimise the template further, if you wish, with the unordered_list filter, if you only wish to display the values. (Note that I’m not certain of how it behaves—it’s possible that this would unmark it as safe. You’d need to try it.)

    <ul>{{ authors|safeseq|unordered_list }}</ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.