DRF 报错:RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

该错误发生于将'django.contrib.contenttypes'注释之后
该组件的功能见如下链接:
https://www.cnblogs.com/xiugeng/p/9831665.html

drf的APIView内部会走认证源码,相关代码导致的报错,怎么解决呢?就是在settings.py中配置上如下两个参数(匿名用户和认证)即可:
https://www.cnblogs.com/Neeo/articles/17048983.html

点击查看代码
REST_FRAMEWORK = {
    "UNAUTHENTICATED_USER": None,
    "UNAUTHENTICATED_TOKEN": None,
}

或者lamda表达式
REST_FRAMEWORK = {
"UNAUTHENTICATED_USER": lambda: None,
"UNAUTHENTICATED_TOKEN": lambda: None,
}

posted on 2024-06-22 21:12  gagagjgj  阅读(18)  评论(0编辑  收藏  举报

导航