django - 在 IPython 中运行 Django shell

标签 django

我尝试在 IPython 中运行 Django shell:

ipython manage.py shell

报如下错误:

Type 'manage.py help ' for help on a specific subcommand.

我搜索并找到了一个流行的解决方案,它可以指导您安装 django.extensions 并在 settings 中启用它。

我正在创建一个最小的项目,而解决方案很繁重。 同时,我必须在每个项目上安装并启用它。

有没有轻量级的方法?

我开始一个新项目, python manage.py shell -i ipython 无法运行

$ python manage.py shell -i ipython
CommandError: Couldn't import ipython interface.
$ ipython --version
6.4.0

最佳答案

只需将 ipython 安装到您的虚拟环境中。 manage.py shell应该默认使用它。

您还可以将 manage.py shell-i option 一起使用显式选择一个 shell(对于常规 Python shell,选项是 ipythonbpythonpython):

python manage.py shell -i ipython

无论哪种方式,您都需要将 ipython 安装到您的环境中,但您无需对项目设置进行任何更改。

关于django - 在 IPython 中运行 Django shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47170049/

相关文章:

python - 将今天日期设置为模型中的默认值

python - 如何预处理传递给 CreateView 的值

python - Django:如何计算一个查询集并返回一个切片而不两次击中数据库?

python - 在 Python 中生成随机十六进制颜色

python - 将 Kivy 应用程序连接到 Django 数据库

django - 如何在Django 2中注册DRF路由器URL模式

django - django如何将字符串转换为模块

Django 模板上下文多个 View

django - 在 django Rest 框架中使用 View 集进行过滤

django - 如何使用 CreateView 过滤表单字段之一中的查询集值?