问题 1
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
处理方法: 修改asgi.py,增加django.setup() 注意:django.setup()要置顶,不能在底部,否则使用daphne启动会报上面的错误。
问题 2
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. . You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
处理方法:
export DJANGO_SETTINGS_MODULE=项目名.settings
问题 3
127.0.0.1:61138 - - [11/Nov/2022:18:29:13] "GET /static/datatables-1.12.1/datatables.min-1.12.1.js" 404 2220
处理方法: 在项目的urls.py中加入下面的代码
def return_static(request, path, insecure=True, **kwargs):
return serve(request, path, insecure, **kwargs)
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'static/(?P<path>.*)$', return_static, name='static')
然后重启 Daphne,刷新页面就可以了
参考链接:https://www.cnblogs.com/hushuning/p/12152539.html
标签:return,settings,ASGI,Django,static,Daphne,path,django,1.12 From: https://blog.51cto.com/liubin0505star/5887766