1
我遇到通過簡單地添加到INSTALLED_APPS
可以「解決」(不migrate
)的錯誤:爲什麼Django Rest Framework試圖驗證請求?
'django.contrib.auth',
'django.contrib.contenttypes',
根據調試輸出,似乎這個錯誤發生,因爲Django的REST框架試圖驗證請求,該請求需要Auth應用程序,該應用程序需要權限和ContentTypes,所有這些都已被刪除。 APIView只使用query_params
從request
,沒有別的。它接受如圖全球DRF設置:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES':(),
'DEFAULT_PERMISSION_CLASSES':(),
'DEFAULT_RENDERER_CLASSES': ('common.rest.JSONRenderer',),
'DEFAULT_CONTENT_NEGOTIATION_CLASS': 'common.rest.IgnoreNegotiation',
}
調試輸出:
RuntimeError at /mac/pins/
Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Request Method: GET
Request URL: http://django/mac/pins/
Django Version: 1.10.5
Python Executable: /home/admin/env/bin/python3.6
Python Version: 3.6.0
Python Path: ['/home/admin/src', '/home/admin/env/bin', '/home/admin/env/lib/python36.zip', '/home/admin/env/lib/python3.6', '/home/admin/env/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6', '/home/admin/env/lib/python3.6/site-packages']
Server time: Fri, 24 Feb 2017 00:54:33 +0000
Installed Applications:
['myapp']
Installed Middleware:
()
Traceback:
File "/home/admin/env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/home/admin/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)
File "/home/admin/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/home/admin/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/admin/env/lib/python3.6/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/home/admin/env/lib/python3.6/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
483. response = self.handle_exception(exc)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/views.py" in handle_exception
443. self.raise_uncaught_exception(exc)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/views.py" in dispatch
471. self.initial(request, *args, **kwargs)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/views.py" in initial
393. self.perform_authentication(request)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/views.py" in perform_authentication
319. request.user
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/request.py" in __getattribute__
379. return super(Request, self).__getattribute__(attr)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/request.py" in user
196. self._authenticate()
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/request.py" in _authenticate
352. self._not_authenticated()
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/request.py" in _not_authenticated
363. if api_settings.UNAUTHENTICATED_USER:
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/settings.py" in __getattr__
220. val = perform_import(val, attr)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/settings.py" in perform_import
163. return import_from_string(val, setting_name)
File "/home/admin/env/lib/python3.6/site-packages/rest_framework/settings.py" in import_from_string
177. module = import_module(module_path)
File "/home/admin/env/lib/python3.6/importlib/__init__.py" in import_module
126. return _bootstrap._gcd_import(name[level:], package, level)
File "/home/admin/env/lib/python3.6/site-packages/django/contrib/auth/models.py" in <module>
6. from django.contrib.contenttypes.models import ContentType
File "/home/admin/env/lib/python3.6/site-packages/django/contrib/contenttypes/models.py" in <module>
138. class ContentType(models.Model):
File "/home/admin/env/lib/python3.6/site-packages/django/db/models/base.py" in __new__
113. "INSTALLED_APPS." % (module, name)
Exception Type: RuntimeError at /mac/pins/
Exception Value: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
爲什麼是嘗試進行身份驗證的要求?我怎樣才能阻止它?