简体   繁体   English

flask.cli.NoAppException:无法在模块“flaskr”中找到 Flask 应用程序或工厂。 使用“FLASK_APP=flaskr:name 指定一个

[英]flask.cli.NoAppException: Failed to find Flask application or factory in module "flaskr". Use "FLASK_APP=flaskr:name to specify one

I am building a python web application using flask and following tutorial from http://flask.pocoo.org/docs/1.0/tutorial/factory/ . I am building a python web application using flask and following tutorial from http://flask.pocoo.org/docs/1.0/tutorial/factory/ . I am running the flask from the parent directory but getting following error.我正在从父目录运行 flask 但出现以下错误。

(venv) E:\python-code\python-web>flask run
 * Serving Flask app "flaskr" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 294-690-396
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello HTTP/1.1" 500 -
Traceback (most recent call last):
  File "e:\python-code\python-web\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "e:\python-code\python-web\venv\lib\site-packages\flask\cli.py", line 95, in find_best_app
    module=module.__name__
flask.cli.NoAppException: Failed to find Flask application or factory in module "flaskr". Use "FLASK_APP=flaskr:name to specify one.
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:43] "GET /hello?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:44] "GET /hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2019 13:10:44] "GET /hello?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -

Please help.请帮忙。

I have tried Running Flask app from cli gives "no module named flaskr" and flask.cli.NoAppException: Failed to find application in module?我试过从cli运行Flask应用程序给出“没有名为flaskr的模块”flask.cli.NoAppException:无法在模块中找到应用程序?

I have found my problem.我发现了我的问题。 I was missing return app as the last statement in my code.我在我的代码中缺少return app作为最后一条语句。 Sorry for confusion and apologies.抱歉给您带来困惑和歉意。

I got that error我得到了那个错误

flask.cli.NoAppException flask.cli.NoAppException: Failed to find Flask application or factory in module "flaskr". flask.cli.NoAppException flask.cli.NoAppException:无法在模块“flaskr”中找到 Flask 应用程序或工厂。 Use "FLASK_APP=flaskr:name to specify one.使用 "FLASK_APP=flaskr:name 指定一个。

I tried all answers, and it got resolved after I changed the function name from create_function to create_app我尝试了所有答案,并在将函数名称从 create_function 更改为create_app 后解决了

is your application dir not named properly?您的应用程序目录未正确命名吗? for example, if you wrote FLASK_APP=flaskr but your project name is something else, you will get this error.例如,如果你写了FLASK_APP=flaskr但你的项目名称是别的,你会得到这个错误。 Also, what is in your flaskr/flaskr/__init__.py file if the project is named flaskr like in the tutorial?另外,如果项目在教程中命名为flaskr ,那么您的flaskr/flaskr/__init__.py文件中是什么?

I followed the instructions just like the official tutorial said but still got the same error.我按照官方教程所说的说明进行操作,但仍然出现相同的错误。

My problem was with the IDE that I was using ( Pycharm )我的问题是我使用的 IDE ( Pycharm )

Even though I had an init .py file in the flaskr directory, it still wasn't considered as a package.即使我在flaskr 目录中有一个init .py 文件,它仍然不被视为一个包。

So I deleted the flaskr directory and created a "new package".所以我删除了flaskr目录并创建了一个“新包”。 Then just copy the code in the init .py and that'll solve the problem然后只需复制init .py中的代码即可解决问题

You can't name the FLASK_APP enviroment var as Flask.py.不能将 FLASK_APP 环境变量命名Flask.py。 Try with another name please and try again.请尝试使用其他名称,然后重试。

No puedes poner el nombre de la variable de ambiente FLASK_APP como Flask.py.没有 puedes poner el nombre de la variable deambite FLASK_APP como Flask.py。 Prueba cambiando el nombre del archivo. Prueba cambiando el nombre del archivo。

Depending on the OS you are using you need to export flaskr in your environment根据您使用的操作系统,您需要在您的环境中导出flaskr

For Linux and Mac:对于 Linux 和 Mac:

export FLASK_APP=flaskr
export FLASK_ENV=development
flask run

For Windows cmd, use set instead of export:对于 Windows cmd,使用 set 而不是 export:

set FLASK_APP=flaskr
set FLASK_ENV=development
flask run

For Windows PowerShell, use $env: instead of export:对于 Windows PowerShell,使用 $env: 而不是 export:

$env:FLASK_APP = "flaskr"
$env:FLASK_ENV = "development"
flask run```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 flask.cli.NoAppException [flaskr教程] - flask.cli.NoAppException [flaskr tutorial] flask.cli.NoAppException:无法导入“flaskr.flaskr” - flask.cli.NoAppException: Could not import "flaskr.flaskr" 错误:无法在模块“app”中找到 Flask 应用程序或工厂。 使用 'FLASK_APP=app:name' 指定一个 - Error: Failed to find Flask application or factory in module 'app'. Use 'FLASK_APP=app:name' to specify one 在模块“app”中找不到 Flask 应用程序或工厂。 使用 'FLASK_APP=app:name' 指定一个 - Failed to find Flask application or factory in module 'app'. Use 'FLASK_APP=app:name' to specify one Docker 运行错误 - 无法在模块“app”中找到 Flask 应用程序或工厂。 使用 "FLASK_APP=app:name 指定一个 - Docker run error - Failed to find Flask application or factory in module "app". Use "FLASK_APP=app:name to specify one flask.cli.NoAppException:无法导入“应用程序” - flask.cli.NoAppException: Could not import "app" flask.cli.NoAppException:应用程序崩溃 - flask.cli.NoAppException: Application crashing 运行烧瓶应用程序时出现“flask.cli.NoAppException” - "flask.cli.NoAppException" while running flask app 运行flask服务器时如何修复flask.cli.NoAppException - How to fix flask.cli.NoAppException when running flask server 运行Flask教程时出错:Flaskr应用 - Error Running Flask Tutorial: Flaskr App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM