I'm following Corey Schafer's tutorial and it all works well on his end but this is what happens on mine...
first, I created flaskblog file
first, I created flaskblog file
from flask import Flask, render_template app = Flask(__name__) posts = [ { 'author': 'Corey Schafer', 'title': 'Blog Post 1', 'content': 'First post content', 'data_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)then home page
<!DOCTYPE html> <html> <head> {% if title %} <title>Flask Blog - {{ title }}</title> {% else %} <title>Flask Blog</title> {% endif %} </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>and about page
<!DOCTYPE html> <html> <head> {% if title %} <title>Flask Blog - {{ title }}</title> {% else %} <title>Flask Blog</title> {% endif %} </head> <body> <h1>About Page</h1> </body> </html>when I try to open about page
http://localhost:5000/about
this is what I get:Error:NameError: name 'About' is not defined
127.0.0.1 - - [23/Jun/2019 01:52:32] "GET /about?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [23/Jun/2019 01:52:32] "GET /about?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [23/Jun/2019 01:52:32] "GET /about?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [23/Jun/2019 01:52:32] "GET /about?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [23/Jun/2019 01:52:32] "GET /about?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
I understand that 'About' is not defined but I don't understand how the code from the tutorial works. What did Corey do so differently?