10

I am trying to build a system in Django without using any of its batteries -- auth, admin etc. The system uses the Django rest framework for the API.

However, when I try to request to an API, I keep getting this error:

Model class django.contrib.auth.models.Permission doesn't declare an explicit
app_label and isn't in an application in INSTALLED_APPS.

I do not want to use django.contrib.auth at all. I did the following inside my DRF API View class:

class NewsPostView(APIView):
    permission_classes = None

    def get(self, request, format=None):
        posts = NewsPost.objects.all()
        serializer = NewsPostSerializer(posts, many=True)
        return Response([])

However, I am still getting the same error. How can I disable auth from DRF?

1
  • show us your settings.py Commented Apr 6, 2018 at 13:24

3 Answers 3

9

I have solved my issue. After @Linovia's response, I checked the docs etc of DRF and changed the following properties:

REST_FRAMEWORK = { 
    'DEFAULT_AUTHENTICATION_CLASSES': [],
    'DEFAULT_PERMISSION_CLASSES': [],
    'UNAUTHENTICATED_USER': None,
}

And everything worked.

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

1 Comment

This should be the accepted answer. Also, you could make it explicit that this configuration goes inside REST_FRAMEWORK settings. Specifically REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [], 'DEFAULT_PERMISSION_CLASSES': [], 'UNAUTHENTICATED_USER': None, }
6

Use AllowAny instead of None. And also your response seems to be returning empty list. use serializer.data for retrieving data

from rest_framework.permissions import AllowAny

class NewsPostView(APIView):
    permission_classes = (AllowAny,)

    def get(self, request, format=None):
        posts = NewsPost.objects.all()
        serializer = NewsPostSerializer(posts, many=True)
        return Response(data=serializer.data)

Comments

3

Make sure you don't use rest_framework.urls and that your settings has:

'DEFAULT_AUTHENTICATION_CLASSES': tuple(),

as well as your views. With some luck, you won't have the authentication imported through another import.

Comments

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.