如何在PyCharm中运行烧瓶外壳? [英] How to run flask shell in PyCharm?
问题描述
我在PyCharm中创建了新的flask项目,但看不到如何在集成的PyCharm python控制台窗口中运行flask shell.
启动控制台时未定义名称应用程序:
我仍然可以在集成的PyCharm终端中运行命令"flask shell",但是它将在没有代码完成,提示,语法检查等的情况下启动.
Flask应用程序在终端中定义:
有什么方法可以在集成的PyCharm python控制台中启动烧瓶外壳?
您可以使用
#步骤1:获取对Flask App实例的引用导入应用app_instance = app.create_app()#我从此处的工厂方法返回应用程序实例,但对于基本的Flask项目,可能是`app.app`#步骤2:推送测试请求上下文,以便您可以执行需要App的工作,例如SQLAlchemyctx = app_instance.test_request_context()ctx.push()
现在,您应该从默认的PyCharm Python Shell中获得 flask shell
的好处以及代码完成和IPython Shell提供的其他好处.
I created new flask project in PyCharm but I can't see how to run flask shell in integrated PyCharm python console window.
Name app is not defined when start console:
I still can run command "flask shell" in integrated PyCharm terminal but it will start without code completion, hints, syntax checks, etc.
Flask app is defined in terminal:
Is there any way to start flask shell in integrated PyCharm python console?
You can use a combination of creating a request context for the Shell (which flask shell
does) and a custom starting script for the PyCharm console.
# 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()
Now you should have the benefits of flask shell
alongside the code completion and other benefits that IPython Shell provides, all from the default PyCharm Python Shell.
这篇关于如何在PyCharm中运行烧瓶外壳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!