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. I think its permission issue.
Solution for me was as pointed out by @ProfNandaa above
I had indeed added this from the homepage example before embarking on the tutorial and hit the same issue.
When I commented out the offending code
from settings.py it all worked fine again.
You probably have set
DjangoModelPermissions
as a default permission class in your settings. Something like:DjangoModelPermissions
can only be applied to views that have a.queryset
property or.get_queryset()
method.Since Tutorial 2 uses FBVs, you probably need to convert it to a CBV or an easy way is to specify a different permission class for that view. You must be using the
api_view
decorator in your view. You can then definepermissions
like below:To resolve the renderer error, you need to add the corresponding renderer to your settings.
In my case, (for tutorial 2,
djangorestframework
ver 3.7.7), it works when I change settings to:I got it working in another way. My logged in user was the superuser which i have created. So i have created another user from admin and made him staff user and provided all the permissions. Then logged in to admin by that user.
In settings.py file i changed code.
And it worked.
There are lots of good solutions already listed here. I also faced the same problem in second tutorial. It was showing:
I changed the
settings.py
to excludeDEFAULT_PERMISSION_CLASSES
like below:Then it runs successfully. I tried this before I have found these answers.