Hugh Mungus
Hugh Mungus

Reputation: 35

Cannot get flask to run

I have been trying to follow the flask tutorial from [http://flask.pocoo.org/docs/1.0/cli/] and i cannot get flask to run.

I get this error

File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 325, in __call__
self._flush_bg_loading_exception()
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 313, in _flush_bg_loading_exception
reraise(*exc_info)
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 302, in _load_app
self._load_unlocked()
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "d:\pyproject\flaskblog\venv\lib\site-packages\flask\cli.py", line 246, in locate_app
'Could not import "{name}".'.format(name=module_name)
flask.cli.NoAppException: Could not import ""hello.py"".

I have tried Reinstalling flask, changing the directory and restarting my computer but to no avail.

I have a hello.py that has the following

from flask import Flask
app = Flask(__name __)

@app.route('/')
def hello_world():
    return 'Hello, World!'

Upvotes: 2

Views: 4822

Answers (2)

aidanfarhi1
aidanfarhi1

Reputation: 1

  1. Make sure in terminal that cd is set to the current project file

  2. Then enter this into terminal (use the file name of your python code in place of app.py)

    • $ export FLASK_APP=app.py
    • $ export FLASK_ENV=development (for debug mode)
    • $ flask run

Upvotes: 0

iamklaus
iamklaus

Reputation: 3770

try this

put the code in a folder named test, inside the folder create a new hello.py, paste the following code there

from flask import Flask

app = Flask(__name__) <<<< no space here

@app.route('/')
def hello_world():
    return 'Hello, World!'

and cd test, set FLASK_APP=hello.py, flask run, works for me.

Try debugging .... flask.cli.NoAppException: Application crashing

Upvotes: 2

Related Questions