Inheritance Flash Template

I am running a jar tutorial and I cannot get template inheritance to work. below are examples of my code

My base.html:

<!DOCTYPE html> <html lang="en"> <head> {% block head %} <link rel="stylesheet" href="style.css" /> <title>{% block title %}{% endblock %} - My Webpage</title> {% endblock %} </head> <body> <div id="content">{% block content %}{% endblock %}</div> <div id="footer"> {% block footer %} &copy; Copyright 2008 by <a href="http://domain.invalid/">you</a>. {% endblock %} </div> </body> </html> 

my child Temp:

 {% extends "base.html" %} {% block title %}Index{% endblock %} {% block head %} {{ super() }} <style type="text/css"> .important { color: #336699; } </style> {% endblock %} {% block content %} <h1>Index</h1> <p class="important"> Welcome to my awesome homepage. </p> {% endblock %} 

my flask script:

 from flask import Flask, render_template app = Flask(__name__) @app.route('/') def home(): return render_template("base.html") if __name__ == "__main__": app.debug = True app.run() 

Is there anything specific that I have to do regarding how I include the child template? Or should I create a basic template differently?

+6
source share
1 answer

Jinja extends works (externally) like a subclass of Python. You do not get an instance of the subclass when you instantiate the parent class, and you do not get the result of the child template when rendering the base template. Instead, create a child template.

 return render_template('child.html') 
+7
source

All Articles