【问题标题】:How can I use ptiPython with Flask-Script together?如何将 ptiPython 与 Flask-Script 一起使用?
【发布时间】:2016-02-15 22:27:08
【问题描述】:

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

【问题讨论】:

    标签: flask ipython django-extensions flask-script


    【解决方案1】:

    Flask-Script 支持ipython 和bpython。您可以创建自定义Shell 类

    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())
    

    【讨论】:

    • 这差不多了,但ptpython.repl.embed 提供的是 Python REPL 而不是 IPython,所以我使用 ptpython.ipython.embed`` instead, and change the use to ``embed(user_ns=context)。你介意更新你的答案吗?我会选择它作为接受的。
    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 2014-08-16
    • 2013-02-26
    • 2013-06-19
    • 2016-01-14
    • 1970-01-01
    • 2019-05-18
    • 2023-04-06
    相关资源
    最近更新 更多