Python Forum
FLASK confuse - 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: FLASK confuse (/thread-41055.html)



FLASK confuse - LennyKiz - Nov-05-2023

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__'?



RE: FLASK confuse - Axel_Erfurt - Nov-05-2023

As the error suggests,

if __name__ == '__main__':