Run shell_plus through PyCharm?

前端 未结 7 652
独厮守ぢ
独厮守ぢ 2020-12-28 17:11

Is there a way for me to configure PyCharm to run shell_plus instead of the default shell?

I\'ve tried putting the text of the manage command in the \'Starting scr

7条回答
  •  醉话见心
    2020-12-28 17:47

    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
    

    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
    

提交回复
热议问题