如何在 python 的 Django shell 中启用历史记录

问题描述 投票:0回答:3

我正在使用

Django
shell_plus
.

readline
rlcompleter
模块安装在那里。

但是我发现当我关闭我的 shell_plus 会话时,我可以返回到我在之前的会话中使用的历史命令。

在我的办公室,我也可以返回到以前的命令。

我需要为此做什么

python django centos
3个回答
8
投票

你可以使用 bpython,它启用了历史记录和许多其他奇妙的功能,如果你使用的是 virtualenv,请使用 pip 安装它。

pip install bpython

或全球

apt-get install bpython

对我来说,这是最棒的 python 交互式 shell。


6
投票

你安装了

IPython
吗?

文档提到那个

默认解析顺序为:bpython、ipython、python。

附言我没有使用过 bpython,但似乎也有历史


0
投票

尝试

shell_plus
,它来自
django-extensions

(venv) ➜ pip install django-extensions

然后安装

ipython
bypython

(venv) ➜ pip install ipython

(venv) ➜ pip install bpython

所以现在您应该将

django-extensions
添加到您的
INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'django_extensions',
    ...
)

还将以下配置添加到您的

settings.py
模块和
INSTALLED_APPS
配置之上:

SHELL_PLUS = "python" # or "bpython" if you installed bpython

然后通过运行以下命令,您可以在 django shell 中获取历史记录、颜色、自动导入和更多种类的好东西:

(venv) ➜ python manage.py shell_plus
© www.soinside.com 2019 - 2024. All rights reserved.