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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:55:10+00:00 2026-06-12T02:55:10+00:00

This seems like a very basic problem but I can’t figure it out. I’m

  • 0

This seems like a very basic problem but I can’t figure it out. I’m passing a list of URLs into an HTML page and trying to print each one out in an href tag. I’m using Flask to run the test server, and can confirm that the variables are being passed in correctly (I can print out the entire list or elements from it).

My app route:

import doaudit # separate Py script that gets these urls

@app.route('/audit', methods = ['GET'])
def audit():
    return render_template('audit.html', listOfUrls = doaudit.listOfUrls)

My template:

<html>
    <head>
        <title>Data Audit</title>   
</head>
<body>

        {% for url in listOfUrls %}        
        <script language="JavaScript">
            document.write( "<a href=\"" + url + "\">linktext</a>" );
        </script>
        {% endfor %}

    </body>
</html>

I’ve tried variations on:

document.write( "<a href=\"" + '{{ listOfUrls[i] }}' + "\">linktext</a>" );

and iterating over all the i’s but that doesn’t work either.

The length of the list can vary, so I need an iterative solution. Thanks in advance.

  • 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-12T02:55:11+00:00Added an answer on June 12, 2026 at 2:55 am

    This is what you want:

    {% for url in listOfUrls %}        
        <script language="JavaScript">
            document.write( "<a href=\"" + {{ url|tojson|safe }} + "\">linktext</a>" );
        </script>
    {% endfor %}
    

    The {{ url }} part tells Jinja2 (the template engine) that this url is actually the variable that you called so in the for url in blabla. Without it, it’s printed as is. You can see it when viewing the source in your browser. This means it will be interpreted as a JS variable, which will be undefined, equivalent to an empty string, which you then see.

    EDIT: added the tojson|safe calls, to make sure it will not break the JS code. You could do it this way : <a href=\"{{ url }}\">linktext</a>. But then a " would break your html/js code.

    EDIT 2: what the tojson filter does, is make it suitable to be put inside JS code. and the safe filter tells the rendering engine that it should not treat it as any text (which should be escaped to show properly in HTML), but treat it as safe text (HTML or not).

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

Sidebar

Related Questions

This seems like it should be very simple but I can't get it to
This seems like it should be something very easy to do, but every time
I have an issue that seems like very flaky behavour, is this a problem
This seems like the simplest Git question, but I can't find ANYTHING on it.
This seems like it should be relatively straightforward, I cannot figure out what I'm
This is a very basic question, but I'd quite like an explanation of why
This seems like it should be very easy...anyway, it is in MS SQL Server
This might seem like a very easy question for some of you folks, but
This seems like a repeated question but i'm not able to get my answer.
This seems like such a simple issue but I cannot find an elegant solution.

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.