当我按下 pycharm 的绿色播放按钮时,我的 Django 项目正常工作。但是当单击调试按钮时,它会显示can't find '__main__' module in ''.
我做了一点 RCA,发现在使用调试选项运行时__spec__被设置为打开。__main__
这是相关的代码段/lib/python3.8/site-packages/django/utils/autoreload.py
# __spec__ is set when the server was started with the `-m` option,
# see https://docs.python.org/3/reference/import.html#main-spec
# __spec__ may not exist, e.g. when running in a Conda env.
if getattr(__main__, '__spec__', None) is not None:
spec = __main__.__spec__
if (spec.name == '__main__' or spec.name.endswith('.__main__')) and spec.parent:
name = spec.parent
else:
name = spec.name
args += ['-m', name]
args += sys.argv[1:]
Run Code Online (Sandbox Code Playgroud)
请帮助我找到解决方法,以便使用 …