carnoteng
carnoteng

Reputation: 29

python Flask does not inherit template

i am learning the template inheritance. I was trying to do it but does not work. i tried; changing location of the file, name of the file, the code itself but still not working. Other flask properties works fine.

Deneme.py:

from flask import Flask, render_template, redirect, url_for

app = Flask(__name__)

@app.route("/")
def home():
    return render_template("go.html")

if __name__ == "__main__":
    app.run(debug=True)

go.html:

<!DOCTYPE html>
<html lang="en">
  <head>
      <title>Template Inheritance</title>
  </head>
  <body>
      <h1> This heading is common in all webpages </h1>
      {% block content %}
      {% endblock %}

  </body>
</html>

side.html:

{% extends "go.html" %}
{% block content %}
  
<h1>Welcome to Home</h1>
  
{% endblock %}

output of the code

both html files are in the template folder. i think it is not about code. what is wrong?

Upvotes: 2

Views: 158

Answers (1)

user47
user47

Reputation: 1199

The problem is in this line of code of your view function:

return render_template("go.html")

You are returning go.html. You need to return side.html which extends the go.html file. Make it:

return render_template("side.html")

Upvotes: 2

Related Questions