Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FLASK confuse
#1
Shocked 
I'm trying to learn how to use Flask in Python

Run into situation I can't resolve.
What is wrong with the following code?

from flask import Flask
app = Flask(_name_)

@app.route('/')
def index():
    return '<h1> Hello from Python flask!</h1>'

if _name_ == '_main_':
    app.run(debug=True)    
#    app.run()
========================================================
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

= RESTART: C:\PYTHON\Workbench\Hello.py

Error:
Traceback (most recent call last): File "C:\PYTHON\Workbench\Hello.py", line 2, in <module> app = Flask(_name_) NameError: name '_name_' is not defined. Did you mean: '__name__'?
Larz60+ write Nov-05-2023, 09:43 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Code modified for you this time. Please use BBCode tags on future posts.
Reply
#2
As the error suggests,

if __name__ == '__main__':
Reply


Forum Jump:

User Panel Messages

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