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

  • Home
  • SEARCH
  • 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 9214265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:56:17+00:00 2026-06-18T01:56:17+00:00

here’s my generalized question: base.html : <html> <head> {% if title %} <title>{{title}}</title> {%

  • 0

here’s my generalized question:

base.html :

<html>
  <head>
    {% if title %}
    <title>{{title}}</title>
    {% else %}
    <title>test</title>
    {% endif %}
  </head>
  <body>
    {% block content %} {% endblock %}
  </body>
</html>

How can I write a function that can directly create a block? maybe something like:

@app.route("/foo")
def foo():
    content = "<h1>this is foo page</h1>"
    return render_html("base.html", content = content)
  • 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-18T01:56:18+00:00Added an answer on June 18, 2026 at 1:56 am

    You are trying to render HTML in your Jinja2 template without HTML escaping. By default, Jinja2 is configured to do automatic escaping of all variables you interpolate.

    This means that

    <h1>this is foo page</h1>
    

    is actually rendered as

    &lt;h1&gt;this is foo page&lt;/h1&gt;
    

    so you don’t accidentally use HTML in your pages where you didn’t mean to. This is very important to protect against Cross Site Scripting (XSS) attacks.

    If you are going to bypass this automatic escaping, and deliberately insert HTML into your templates, you must make sure you know what you are doing – never allow unescaped user input to get into these variables.

    With the background lesson and security warnings out of the way, if you do know what you are doing, you can explicitly mark values as “safe” in your template, so they will not be escaped. Just use Jinja2’s builtin filter, safe, like so:

      <body>
        {{ content | safe }}
      </body>
    

    In your case, I think you also wanted to have a block, so you can override with template inheritance. For an example of that, play with this complete example app

    test.py:

    import flask
    
    app = flask.Flask(__name__)
    
    @app.route("/foo")
    def foo():
        content = "<h1>this is foo content</h1>"
        return flask.render_template("base.html", content=content)
    
    @app.route("/bar")
    def bar():
        content = "<h1>this is bar content</h1>"
        return flask.render_template("child.html", content=content)
    
    if __name__ == "__main__":
        app.run(debug=True)
    

    templates/base.html:

    <html>
      <head>
        {% if title %}
        <title>{{title}}</title>
        {% else %}
        <title>test</title>
        {% endif %}
      </head>
      <body>
        {% block content %}{{ content | safe }}{% endblock %}
      </body>
    </html>
    

    templates/child.html:

    {% extends "base.html" %}
    {% block content %}
      {{ super() }}
      <h2>And this bit comes from the child template</h2>
    {% endblock %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my html: <ul id=sub_nav class=block_hide trim no_list no_line style=display: block; left: 524.5px;>
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
I am using JSon response to parse title,date content and thumbnail images and place
here Html given below <div class=navBulletsWrapper> <div rel=0 class=></div> <div rel=1 class=></div> <div rel=2
Here is what I want to do. Use this HTML line and have the
Here is the code in which i am having the problem- <!DOCTYPE html> <html>
Here's a newbie question, but how do I use dates for the x-axis in
here is the html <table> <tr> <td class=break>mono</td> </tr> <tr> <td>c1</td> <td>c2</td> <td>c3</td> </tr>
Here are some facts about my app followed by a question My app has

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.