1

I have DRF project documented with drf_yasg and validator rest framework simple jwt.

File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\core\accounts\api\v1\urls\accounts.py", line 5, in <module>
    from .. import views
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\core\accounts\api\v1\views.py", line 4, in <module>
    from rest_framework.authtoken.views import ObtainAuthToken
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\venv\Lib\site-packages\rest_framework\authtoken\views.py", line 11, in <module>
    class ObtainAuthToken(APIView):
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\venv\Lib\site-packages\rest_fra  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\core\accounts\api\v1\views.py", line 4, in <module>
    from rest_framework.authtoken.views import ObtainAuthToken
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\venv\Lib\site-packages\rest_framework\authtoken\views.py", line 11, in <module>
    class ObtainAuthToken(APIView):
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\venv\Lib\site-packages\rest_fra    from rest_framework.authtoken.views import ObtainAuthToken
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\venv\Lib\site-packages\rest_framework\authtoken\views.py", line 11, in <module>
    class ObtainAuthToken(APIView):
  File "C:\Users\ASUS\OneDrive\Desktop\django\Django-Advance\venv\Lib\site-packages\rest_framework\authtoken\views.py", line 21, in ObtainAuthToken
    coreapi.Field(
    ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'Field'

this is my requirements.txt file:

# general modules
django<4.3,>4.2
python-decouple
Pillow

# third party modules
djangorestframework
markdown
django-filter
drf-yasg[validation]

djangorestframework-simplejwt[crypto]
# deployment modules

this is my created CustomObtainAuthToke class:

class CustomObtainAuthToken(ObtainAuthToken):
    serializer_class = CustomAuthTokenSerializer

    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(
            data=request.data, context={"request": request}
        )
        serializer.is_valid(raise_exception=True)
        user = serializer.validated_data["user"]
        token, created = Token.objects.get_or_create(user=user)
        return Response(
            {
                "user_id": user.pk,
                "email": user.email,
                "token": token.key,
            }
        )

and this is how I import that in line 4 from rest_framework.authtoken.views import ObtainAuthToken

I tried to reversion the requirements.txt modules. I changed the DRF to different version for testing purposes to 3.12, 3.13, 3.14, 3.15 and the latest version of Django Rest Framework installed

1 Answer 1

1

Beginning with version 3.12, openapi schema creation was introduced without using coreapi as the default for schema creation.

Using 3.12 or later versions will resolve the error If you must use coreapi after the version update, please add the following settings to settings.py and install coreapi package.

REST_FRAMEWORK = {
    ...: ...,
    "DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema",
}

Please refer to this article.

Sign up to request clarification or add additional context in comments.

3 Comments

I installed it before in Rest Framework settings as you said, but can you explain me relevant of coreapi with drf_yasg when I used drf spectacular i didn't have this issues
When you used the drf 3.12 or later version, the drf_yasg package had a problem, but used the drf_spectacular package, didn't it have a problem above?
@Anatoliny No I didn't have such a problem before this is my first time I encounter to this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.