我在 PyCharm 中创建了新的 Flask 项目,但我看不到如何在集成的 PyCharm python 控制台窗口中运行 Flask shell。
Name app is not defined when start console:
我仍然可以在集成 PyCharm 终端中运行命令“flask shell”,但它将在没有代码完成、提示、语法检查等的情况下启动。
Flask 应用程序在终端中定义:
Is there any way to start flask shell in integrated PyCharm python console?
您可以组合使用为 Shell 创建请求上下文 (which flask shell
确实)和一个PyCharm 控制台的自定义启动脚本.
# Step 1: acquire a reference to your Flask App instance
import app
app_instance = app.create_app()
# I return app instance from a factory method here, but might be be `app.app` for basic Flask projects
# Step 2: push test request context so that you can do stuff that needs App, like SQLAlchemy
ctx = app_instance.test_request_context()
ctx.push()
现在你应该有以下好处flask shell
除了 IPython Shell 提供的代码完成和其他好处之外,所有这些都来自默认的 PyCharm Python Shell。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)