Error annot apply DjangoModelPermissions on a view that does not have queryset property or overrides the get queryset method

0 votes

I am getting the error ".accepted_renderer not set on Response resp api django".

I am following the django rest-api tutorial. Django version i am using 1.8.3 I followed the tutorial till first part. It worked properly. But when i continued the 2nd part in sending response, i got an error

Cannot apply DjangoModelPermissions on a view that does not have `.queryset` property or overrides the `.get_queryset()` method.

Then i tried other ways i got

.accepted_renderer not set on Response resp api django

Please help me out!

Jun 25, 2020 in Python by kartik
• 37,510 points
3,596 views

1 answer to this question.

0 votes

Hello @kartik,

You probably have set DjangoModelPermissions as a default permission class in your settings.

Something like:

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.DjangoModelPermissions',
    )
}

DjangoModelPermissions can only be applied to views that have a .queryset property or .get_queryset() method.

You can then define permissions like below:

from rest_framework.decorators import api_view, permission_classes
from rest_framework import permissions

@api_view([..])
@permission_classes((permissions.AllowAny,))
def my_view(request)
    ...

To resolve the renderer error, you need to add the corresponding renderer to your settings.

REST_FRAMEWORK = {
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.<corresponding_renderer>',
        ...
    )

Hope it helps!!

Thank You!!

answered Jun 25, 2020 by Niroj
• 82,880 points

Related Questions In Python

0 votes
1 answer

How does Python know whether a variable in the class is a method or a variable?

In python objects/variables are wrapped into methods ...READ MORE

answered Sep 18, 2018 in Python by aryya
• 7,450 points
936 views
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,210 points
2,362 views
+1 vote
5 answers
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,880 points
2,041 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,880 points
1,190 views
0 votes
1 answer

Error: (2_0.W001) has a route that contains '(?P<', begins with a '^', or ends with a '$'

Hello @kartik, The new path() syntax in Django 2.0 does ...READ MORE

answered Jul 2, 2020 in Python by Niroj
• 82,880 points
4,665 views
0 votes
1 answer

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Hello @kartik, Since different users might have different ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,880 points
22,885 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP