Run shell_plus through PyCharm?(通过 PyCharm 运行 shell_plus?)
问题描述
有没有办法让我配置 PyCharm 以运行 shell_plus而不是默认外壳?
Is there a way for me to configure PyCharm to run shell_plus instead of the default shell?
我尝试将管理命令的文本放在启动脚本"中,但随后我得到了以下内容django_manage_shell.run("/Users/cmason/counsyl/code/website/counsyl/product")导入操作系统导入系统
I've tried putting the text of the manage command in the 'Starting script' but then I get the folloiwing django_manage_shell.run("/Users/cmason/counsyl/code/website/counsyl/product") import os import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
# The new Django 1.4 default manage.py wants "from django..." before
# importing settings, but we usually tinker with sys.path in
# settings_local.py, which is called from settings.py. Importing
# settings.py works but does mean some double importing. Luckily that
# module does very little work.
import settings
# appease pyflakes; don't ever do this in
# non-super-meta-namespace-trickery code
settings
from django.core.management import execute_from_command_line
execute_from_command_line("shellplus")
它并没有真正运行 shell_plus.
and it hasn't really run shell_plus.
似乎启动脚本"是在默认情况下发生的,而不是默认情况下发生的.
It seems like the 'Starting script' happens in addition to rather than instead of the default.
Shell_plus 自动导入所有 Django 模型类,等等.
Shell_plus automatically imports all Django model classes, among other things.
推荐答案
我通过挂钩到 shell_plus 代码来自动加载模型对象.我将此附加到 Preferences > 中的默认启动脚本中.构建、执行、部署 >控制台 >Django 控制台:
I got the model objects auto-loading by hooking into the shell_plus code. I appended this to the default startup script in Preferences > Build, Execution, Deployment > Console > Django Console:
from django_extensions.management import shells
from django.core.management.color import color_style
imported_items = shells.import_objects({}, color_style())
for k, v in imported_items.items():
globals()[k] = v
这是在 PyCharm 2018.3.3 Pro 上
This was on PyCharm 2018.3.3 Pro
为了完整起见,这是启动脚本的全部内容:
For completeness, this was the full content of starting script:
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
from django_extensions.management import shells
from django.core.management.color import color_style
imported_items = shells.import_objects({}, color_style())
for k, v in imported_items.items():
globals()[k] = v
这篇关于通过 PyCharm 运行 shell_plus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 PyCharm 运行 shell_plus?
基础教程推荐
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 包装空间模型 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
