通过 PyCharm 运行 shell_plus? [英] Run shell_plus through PyCharm?

查看:22
本文介绍了通过 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆