0

I am getting this Traceback (most recent call last) when running my python-flask web app.

**Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/flask/cli.py", line 325, in __call__
    self._flush_bg_loading_exception()
  File "/Library/Python/2.7/site-packages/flask/cli.py", line 313, in _flush_bg_loading_exception
    reraise(*exc_info)
  File "/Library/Python/2.7/site-packages/flask/cli.py", line 302, in _load_app
    self._load_unlocked()
  File "/Library/Python/2.7/site-packages/flask/cli.py", line 317, in _load_unlocked
    self._app = rv = self.loader()
  File "/Library/Python/2.7/site-packages/flask/cli.py", line 372, in load_app
    app = locate_app(self, import_name, name)
  File "/Library/Python/2.7/site-packages/flask/cli.py", line 246, in locate_app
    'Could not import "{name}".'.format(name=module_name)
NoAppException: Could not import "teosblog.py
flask run
python teosblog".**

from flask import Flask app = Flask(name)

@app.route("/") def hello(): return "

Hello World!

"

I am running the server on the terminal with: "cd Flask_Blog", "export FLASK_DEBUG=1"

this than runs the server and gives me the ip to run on my WebBrowser, but I have no success whatsoever! Instead i get the above error.

I have also trying initializing the flask module by assigning the "flask.init()" code, but I still get the error on the web Browser!

am i doing something wrong? Can i get some assistances? thanks

Ps: I also tried using the python interpreter to run my app by adding the following to my code:

if name == 'main': app.run(debug=True)

but I still get the trace back.

  • "this than runs the server... ": no, it doesn't. How do you start the server? Is the directory Flask_Blog the actual directory your code resides? What do you type in the address bar of your browser to reach the server? In "if name=='main' name as well as main should be surrounded by double underscores. Did you type that or what you typed in the question? – Menno Hölscher Jan 19 '19 at 14:49
  • Hi, you're right, I was doing it all wrong, not on IDE itself but on the terminal, I saw an advice from previous answers and I tried it. This is how I was trying to run the server before: cd Flask-Blog, "export FLASK_DEBUG=1" then "flask run". From this I could get an IP Address to run on my web browser but I wasn't initializing the flask module from the terminal it's self! – Teodorico Maziviala Jan 19 '19 at 15:20

1 Answers1

1

It says explicitly what the problem is.

'Could not import "{name}".'.format(name=module_name)

Try with __name__.

app = Flask(__name__)

Might be useful:
- What does if name == “main”: do?
- Flask('application') versus Flask(name)
- Flask minimal application

Besides, Python 3 is over 10 years old. If you can, ditch 2.7 in favor of 3.6 or 3.7.

Tom Wojcik
  • 5,471
  • 4
  • 32
  • 44
  • Sorry, i am new to programming and still don't understand most of the functions and Syntax! i just tried all the options provided, I read the documentation but i still don't understand why this is not working! – Teodorico Maziviala Jan 19 '19 at 12:30