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-
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
<!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
<!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.