使用uvicorn启动django时引发了以下错误
django.core.exceptions.ImproperlyConfigured: Requested settings, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
原因及解决
1.原因: 排查了很久,最后发现报错来源于包的导入
在__init__.py文件中用了下图所示的包导入语句, 导致了uvicorn无法启动django, 如下图:
2.解决:
移除放置在__init__.py中的导入语句, 在需要使用这个包的py文件中重新导入包,最后可正常启动django, 如下图
导入:
正常启动: