Python Forum

Full Version: starting with flask: code does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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)
Thonx!

Yep, you are right and I fixed it!