问题描述
仅在auth / users / me /上执行get请求会导致此错误,提示如上所述。找不到任何有帮助的东西。您能帮我弄清楚该错误的出处以及如何解决。我正在关注的教程的链接如下。刚刚设置了一个新项目,并用jwt安装了djoner。以下是详细的错误消息
Djoner链接 https://djoser.readthedocs.io/en/latest/sample_usage.html
Internal Server Error: /auth/users/me/
Traceback (most recent call last):
File "/home/prashant/project/env/lib/python3.8/site-packages/django/core/handlers/exception.py",line 34,in inner
response = get_response(request)
File "/home/prashant/project/env/lib/python3.8/site-packages/django/core/handlers/base.py",line 115,in _get_response
response = self.process_exception_by_middleware(e,request)
File "/home/prashant/project/env/lib/python3.8/site-packages/django/core/handlers/base.py",line 113,in _get_response
response = wrapped_callback(request,*callback_args,**callback_kwargs)
File "/home/prashant/project/env/lib/python3.8/site-packages/django/views/decorators/csrf.py",line 54,in wrapped_view
return view_func(*args,**kwargs)
File "/home/prashant/project/env/lib/python3.8/site-packages/rest_framework/viewsets.py",line 125,in view
return self.dispatch(request,*args,**kwargs)
File "/home/prashant/project/env/lib/python3.8/site-packages/rest_framework/views.py",line 509,in dispatch
response = self.handle_exception(exc)
File "/home/prashant/project/env/lib/python3.8/site-packages/rest_framework/views.py",line 469,in handle_exception
self.raise_uncaught_exception(exc)
File "/home/prashant/project/env/lib/python3.8/site-packages/rest_framework/views.py",line 480,in raise_uncaught_exception
raise exc
File "/home/prashant/project/env/lib/python3.8/site-packages/rest_framework/views.py",line 497,in dispatch
self.initial(request,line 415,in initial
self.check_permissions(request)
File "/home/prashant/project/env/lib/python3.8/site-packages/rest_framework/views.py",line 333,in check_permissions
self.permission_denied(
TypeError: permission_denied() got an unexpected keyword argument 'code'
[28/Oct/2020 17:40:20] "GET /auth/users/me/ HTTP/1.1" 500 16964
settings.py
# Security WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,# or allow read-only access for unauthenticated users.
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',],'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',}
INSTALLED_APPS = [
'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','rest_framework','rest_framework.authtoken','djoser',]
# JWT Settings
SIMPLE_JWT = {
'AUTH_HEADER_TYPES': ('JWT',),}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',]
ROOT_URLconf = 'channels.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates','Dirs': [],'APP_Dirs': True,'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',},]
Wsgi_APPLICATION = 'channels.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3','NAME': 'channelsdb',}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS,JavaScript,Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
urls.py
from django.contrib import admin
from django.urls import path,include,re_path
from . import views
urlpatterns = [
path('admin/',admin.site.urls),re_path('^auth/',include('djoser.urls')),include('djoser.urls.jwt')),path('home',views.Home.as_view(),name='home'),]
views.py
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.status import HTTP_200_OK
class Home(APIView):
def post(self,request):
return Response({'data':'hello thanks for loggin\' in'},status=HTTP_200_OK)