"时得到 "flask db init"-6ren"> "时得到 "flask db init"-这里是 python 的新手。使用 CRUD-PythonFlask 中的 PyCharm 社区版处理一个基本项目网站。在执行迁移步骤时,在命令 flask db init 后出现如下错误: Trac-6ren">
gpt4 book ai didi

python - 运行 "KeyError: "时得到 "flask db init"

转载 作者:行者123 更新时间:2023-12-03 23:21:28 25 4
gpt4 key购买 nike

这里是 python 的新手。使用 CRUD-PythonFlask 中的 PyCharm 社区版处理一个基本项目网站。在执行迁移步骤时,在命令 flask db init 后出现如下错误:

Traceback (most recent call last):
File "C:\Python27\Lib\runpy.py", line 174, in_run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\elkkanah\PycharmProjects\aquauk\venv\Scripts\flask.exe\__main__.py", line 9, in <m
odule>
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 894, in
main
cli.main(args=args, prog_name=name)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 557, in
main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 717, i
n main
rv = self.invoke(ctx)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 1137,
in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 1137,
in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 956, i
n invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\core.py", line 555, i
n invoke
return callback(*args, **kwargs)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\click\decorators.py", line
17, in new_func
return f(get_current_context(), *args, **kwargs)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 411, in
decorator
with __ctx.ensure_object(ScriptInfo).load_app().app_context():
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 377, in
load_app
raise_if_not_found=False)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 254, in
locate_app
return find_best_app(script_info, module)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 76, in
find_best_app
app = call_factory(script_info, app_factory)
File "c:\users\elkkanah\pycharmprojects\aquauk\venv\lib\site-packages\flask\cli.py", line 114, in
call_factory
return app_factory(script_info)
File "C:\Users\elkkanah\PycharmProjects\aquauk\app\__init__.py", line 19, in create_app
app.config.from_object(app_config[config_name])
KeyError: <flask.cli.ScriptInfo object at 0x0000000003C05B70>
__init__.py文件:
# app/__init__.py

# third-party imports
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_migrate import Migrate

# local imports
from config import app_config

# db variable initialization
db = SQLAlchemy()
login_manager = LoginManager()


def create_app(config_name):
app = Flask(__name__, instance_relative_config=True)
app.config.from_object(app_config[config_name])
app.config.from_pyfile('config.py')
db.init_app(app)

login_manager.init_app(app)
login_manager.login_message = "You must be logged in to access this page."
login_manager.login_view = "auth.login"

migrate = Migrate(app, db)

from app import models

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

return app

需要帮助来解决问题。任何帮助表示赞赏。

最佳答案

我在为 FLASK_APP 环境变量使用 python 文件而不是使用模块(或 flask 术语中的应用程序)时遇到过这种情况,即:

$ export FLASK_APP=flask_app.py

代替
$ export FLASK_APP=flask_app:app

我认为你可能完全错过了 FLASK_APP,因为 flask db init 表现出这种行为。

关于python - 运行 "KeyError: <flask.cli.ScriptInfo object at 0x0000000003C05B70>"时得到 "flask db init",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54107915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com