I am facing problem while running this line of code in the terminal:
$ sudo python app.py
And the Traceback is :
Traceback (most recent call last):
File "app.py", line 7, in <module>
APP = flask.Flask(__name__)
NameError: name 'flask' is not defined
sudo pip install flask
Requirement already satisfied (use --upgrade to upgrade): flask in
/usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in
/usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in
/usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade):
itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in
/usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)
Cleaning up...
Any help would be appreciated.
The Python "NameError: function is not defined" occurs when we try to call a function that is not declared or before it is declared. To solve the error, make sure you haven't misspelled the function's name and call it after it has been declared.
The error name 'flask' is not defined comes when you are not properly using the flask module. You are importing a flask module instead of flask. Flask() you are using a flask module.
The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.
__name__ is just a convenient way to get the import name of the place the app is defined. Flask uses the import name to know where to look up resources, templates, static files, instance folder, etc.
if flask is not installed:
pip install flask
then
import flask
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With