Python Forum
starting with flask: code does not work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: starting with flask: code does not work (/thread-5752.html)



starting with flask: code does not work - Peter_EU - Oct-19-2017

Hallowings,


I am following tutorials of https://www.youtube.com/watch?v=OuDOr32ZHE0

I started writing my first python/html document (pip installed, flask too, virtual environment activated, did my first "Hello world" on 127.0.0.1:5000 and next moving to smt. tiny more complicated)

and I am getting error messages. I am not certain what might be the problem, console says smt. about TemplateNotFound: test.html(???)

so here is the code:

python doc (app.py):
from flask import Flask, render_template
app = Flask(__name__)

@app.route("/")
def index():
    tv_show = "The Office"
    return render_template("test.html", show = tv_show)


if __name__ == "__main__":
    app.run()
and HTML file (test.html):

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Hallo World</title>
</head>
<body>
    <h1>My favorite TV show is {{ show }}</h1>
</body>
</html>
if anyone has any idea, thanks for help.


Sincerely,

the Noob Noob


RE: starting with flask: code does not work - snippsat - Oct-19-2017

You must a have a templates folder.
The way to set it up.
my_page/
  |-- app.py 
  templates/
    |-- test.html
  static\ # ccs,js,images ..ect goes in here in own folders
Always set debug to True,so you get good error messages.
Just remember to turn it off if deploy to a web host,as public web site/app.
app.run(debug=True)


RE: starting with flask: code does not work - Peter_EU - Oct-20-2017

Thonx!

Yep, you are right and I fixed it!