Click here to Skip to main content
15,941,615 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a folder named Python Project 01. It has 2 sub folders templates(for html)(it has two folders- home.html and about.html) and flaskblog (for python )


The code for my flaskblog is-

Python
from flask import Flask, render_template
app = Flask(__name__)

posts = [
   {      
    'author': 'Corey Schafer', 
     'title': 'Blog Post 1',
     'content': 'First post content',
     'date_posted': 'April 20, 2018'
   } ,
   
   {
     'author':'Jane Doe',
     'title':'Blog Post 2',
     'content':'Second post content',
     'date_posted':'April 21,2018'
   }
]

@app.route("/")
@app.route("/home")
def home():
    return render_template('home.html', posts=posts)
     
     
@app.route("/about")
def about():
     return render_template('about.html', title='About')
     
     
if __name__=="__main__":
    app.run(debug=True)


The code for my 1st template folder i.e home.html is

HTML
<!DOCTYPE html>
<html>
<head>
{% if title %}
<title>Flask Blog - {{title}}</title>
{% else %}
<title>
Flask Blog
</title>
{% end if %}
</head>
<body>
{% for post in posts %}
<h1>{{post.title}}</h1>
<p>
By{{post.author}} on {{post.date_posted}}
</p>
<p>
{{post.content}}
</p>
{% endfor %}
</body>
</html>



The code for my 2nd template folder i.e about.html is


HTML
<!DOCTYPE html>
<html>
<head>
{% if title %}
<title>Flask Blog - {{title}}</title>
{% else %}
<title>
Flask Blog
</title>
{% end if %}
</head>
<body>
<h1>About Page</h1>
</body>
</html>


What I have tried:

i am not sure to how to solve this error so i have not tried anything yet.Kindly help me solve this issue.
Posted
Updated 25-Aug-22 19:22pm

1 solution

In Jinja, endif is one word, not two end if: Template Designer Documentation — Jinja Documentation (3.0.x)[^]
Jinja
{% if title %}
<title>Flask Blog - {{title}}</title>
{% else %}
<title>
Flask Blog
</title>
{% end if %}
Should be:
Jinja
{% if title %}
<title>Flask Blog - {{title}}</title>
{% else %}
<title>
Flask Blog
</title>
{% endif %}
 
Share this answer
 
Comments
Aalam Pratap Bedi 26-Aug-22 1:43am    
Thanks for helping.
OriginalGriff 26-Aug-22 2:22am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900