如何将 ptiPython 与 Flask-Script 一起使用?

How can I use ptiPython with Flask-Script together?

在 Django 中,在启用 Django-Extensions 插件以强制执行 Django-Shell 后,我可以使用 ptiPython 而不是 IPython。在 Flask 世界中,另一种似乎是 Flask-Script,我四处搜索但找不到任何可以将 ptiPython 与 Flask-Shell 一起使用的东西。

Flask-Script支持ipythonbpython。您可以创建自定义 Shell class

from flask.ext.script import Shell
from ptpython.ipython import embed

class PtShell(Shell):
    def run(self, **kwargs):
        context = self.get_context()
        embed(user_ns=context)

manager.add_command("shell", PtShell())