Python Forum
starting with flask: code does not work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
starting with flask: code does not work
#1
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
Reply
#2
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)
Reply
#3
Thonx!

Yep, you are right and I fixed it!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code injector (scapy), replace does not work iago 0 1,747 Jun-27-2020, 03:05 PM
Last Post: iago
  [FLASK] How to structure the code in my case ? Fre3k 4 2,660 May-04-2020, 04:43 PM
Last Post: Fre3k
  Flask return http status code 200 but web browser not recive supernoobs 2 10,730 Dec-29-2018, 09:27 PM
Last Post: Unisoftdev
  How to make my code work with asyncio? DevinGP 0 2,734 Jan-09-2018, 06:21 PM
Last Post: DevinGP
  how to place Flask code on a public web server rarevesselt 6 6,959 Oct-04-2017, 07:32 AM
Last Post: rarevesselt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020