gpt4 book ai didi

python - 通过PyCharm运行shell_plus吗?

转载 作者:行者123 更新时间:2023-12-04 02:07:41 25 4
gpt4 key购买 nike

我是否可以将PyCharm配置为运行shell_plus而不是默认Shell?

我尝试将manage命令的文本放在“启动脚本”中,但随后出现以下问题
django_manage_shell.run(“ /用户/ cmason / counsyl / code /网站/ counsyl / product”)
导入操作系统
导入系统

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。

似乎“启动脚本”是除了默认值以外而不是默认值发生的。

Shell_plus会自动导入所有Django模型类。

最佳答案

通过连接到shell_plus代码,我可以自动加载模型对象。我将其附加到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上

为了完整起见,这是启动脚本的全部内容:

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

关于python - 通过PyCharm运行shell_plus吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19868449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com