在IPython中运行Django Shell [英] Run Django shell in IPython
问题描述
我尝试在IPython中运行Django shell:
I attempt to run a Django shell in IPython:
ipython manage.py shell
它报告以下错误:
类型
Type 'manage.py help ' for help on a specific subcommand.
我搜索并找到了一个流行的解决方案,该解决方案可指导您安装 django.extensions
并在设置
中启用它。
I searched and found a popular solution which guides you to install django.extensions
and to enable it in settings
.
I解决方案繁重时,我正在创建一个最小的项目。
同时,我必须在每个项目上安装并启用它。
I am creating a minimal project while the solution is heavy. Meanwhile, I have to install and enable it on every project.
有一种轻巧的方法吗?
我开始一个新项目,
python manage.py shell -i ipython
无法工作
I start a new project,
python manage.py shell -i ipython
fails to work
$ python manage.py shell -i ipython
CommandError: Couldn't import ipython interface.
$ ipython --version
6.4.0
推荐答案
只需将 ipython
安装到您的virtualenv中。 manage.py shell
应该默认使用它。
Simply install ipython
into your virtualenv. manage.py shell
should use it by default.
您还可以将 manage.py shell
与< a href = https://docs.djangoproject.com/zh-CN/1.11/ref/django-admin/#cmdoption-shell-interface rel = noreferrer> -i
选项以明确选择外壳程序(选项为 ipython
, bpython
或 python
(用于常规Python Shell)):
You can also use manage.py shell
with the -i
option to explicitly select a shell (the options are ipython
, bpython
, or python
for a regular Python shell):
python manage.py shell -i ipython
无论哪种方式,您都需要安装 ipython
进入您的环境,但是您无需对项目设置进行任何更改。
Either way, you do need to install ipython
into your environment, but you don't need to make any changes to your project settings.
这篇关于在IPython中运行Django Shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!