Home > Back-end >  Why am I getting ' NameError: name '_name_' is not defined' in this code intende
Why am I getting ' NameError: name '_name_' is not defined' in this code intende

Time:11-18

I've just installed Flask on my computer and I am testing some code to see if Flask works. But everytime I run the following code on my computer from my command line a NameError: name '_name_' is not defined error appears. What is going wrong?

from flask import Flask

app = Flask(_name_)

def hello@app.route("/")
    _world() -> str:
    return "Hello world from Flask!"

app.run()   

CodePudding user response:

It's supposed to prefixed and suffixed with two underscores, not just one!

So it's app = Flask(__name__) not app = Flask(_name_)

CodePudding user response:

it should be double underscore for __name__

app = Flask(__name__)

CodePudding user response:

Because it should be double underscore. __name__

app = Flask(__name__)
  • Related