Hello,
just got back after long time to DRF and im trying to implement login /
signup api endpoint.
Signup serializer.py:
class UserCreateSerializer(ModelSerializer):
class Meta:
model = CustomUser
fields = ('email', 'password', 'user_type')
extra_kwargs = {"password":
{"write_only": True
},
}
def create(self, validate_data):
email = validate_data['email']
password = validate_data['password']
user_object = CustomUser(
email=email,
)
user_object.set_password(password)
user_object.save()
return validate_data
Signup viewset.py
class UserCreateApiView(CreateAPIView):
"""
API endpoint that creates a user
"""
queryset = CustomUser.objects.all()
serializer_class = UserCreateSerializer
permission_classes = [AllowAny, ]
urls.py
path('auth/signup/', viewset.UserCreateApiView.as_view(), name='api-signup'),
Everything works fine and as expected, the problem is that the browsable
api raise the exception :
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/api/v1/auth/signup/
Django Version: 2.2.3
Python Version: 3.7.3
Installed Applications:
['widget_tweaks',
'rest_framework',
'jet.dashboard',
'jet',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps.root',
'apps.user',
'apps.authentication',
'apps.dash',
'api.api_authentication']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'BioActHerb.middleware.cookie_middleware.LanguageCookieMiddleware']
Traceback:
File
"C:\Users\Harrys\Anaconda3\lib\site-packages\django\core\handlers\exception.py"
in inner
34. response = get_response(request)
File
"C:\Users\Harrys\Anaconda3\lib\site-packages\django\core\handlers\base.py"
in _get_response
115. response = self.process_exception_by_middleware(e,
request)
File
"C:\Users\Harrys\Anaconda3\lib\site-packages\django\core\handlers\base.py"
in _get_response
113. response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File
"C:\Users\Harrys\Anaconda3\lib\site-packages\django\views\decorators\csrf.py"
in wrapped_view
54. return view_func(*args, **kwargs)
File
"C:\Users\Harrys\Anaconda3\lib\site-packages\django\views\generic\base.py"
in view
71. return self.dispatch(request, *args, **kwargs)
File "C:\Users\Harrys\Anaconda3\lib\site-packages\rest_framework\views.py"
in dispatch
495. response = self.handle_exception(exc)
File "C:\Users\Harrys\Anaconda3\lib\site-packages\rest_framework\views.py"
in handle_exception
455. self.raise_uncaught_exception(exc)
File "C:\Users\Harrys\Anaconda3\lib\site-packages\rest_framework\views.py"
in dispatch
492. response = handler(request, *args, **kwargs)
File "C:\Users\Harrys\Anaconda3\lib\site-packages\rest_framework\views.py"
in http_method_not_allowed
169. raise exceptions.MethodNotAllowed(request.method)
File
"C:\Users\Harrys\Anaconda3\lib\site-packages\rest_framework\exceptions.py"
in __init__
198. detail =
force_text(self.default_detail).format(method=method)
Exception Type: KeyError at /api/v1/auth/signup/
Exception Value: 'method"'
If i test the endpoint via POSTMAN it works fine for post method but for
get method it returns the whole exception. The get method should just
return "method not allowed".
Any idea what is happening?
Thank's in advance.
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-rest-framework/86a13219-5740-495f-b2a8-27ce197dd5e8%40googlegroups.com.