Я использовал django-phonenumber-field в качестве поля модели моего номера телефона и сериализатора.Это сработало, и все было хорошо.Теперь я пытаюсь внедрить Json Web Token в Django Rest Framework этих двух пакетов, djsoer и djangorestframework-jwt .Я управляю и перемещаю старую (django 1.11) кодовую базу в Django2.Прямо сейчас, когда я пытаюсь создать новый токен авторизации, я получаю внутреннюю ошибку сервера.Сообщение об ошибке:
TypeError: Object of type 'PhoneNumber' is not JSON serializable
Я знаю, что за это отвечает объект PhoneNumber из пакета Django-phonenumber-field.Однако стек ошибок находится в djangorestframework-jwt .Как добавить / передать сериализатор PhoneNumber в JWT?
[Я не понимаю, какая кодовая база необходима, поэтому я не добавил ни одной.Спросите меня, я опишу / добавлю позже.]
TIA.
Edit # 1:
Traceback
Internal Server Error: /api/auth/create_token/
Traceback (most recent call last):
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework_jwt/views.py", line 57, in post
if serializer.is_valid():
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework/serializers.py", line 236, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework/serializers.py", line 437, in run_validation
value = self.validate(value)
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework_jwt/serializers.py", line 60, in validate
'token': jwt_encode_handler(payload),
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/rest_framework_jwt/utils.py", line 95, in jwt_encode_handler
api_settings.JWT_ALGORITHM
File "/home/a_o/.local/share/virtualenvs/conveyanceappbackend-Y2Y7Ynbu/lib/python3.6/site-packages/jwt/api_jwt.py", line 62, in encode
cls=json_encoder
File "/usr/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)