If you get the error Request object has no attribute “accepted_renderer” or WSGIRequest object has no attribute “accepted_renderer” when using Django Rest Framework and attempting to add a custom BaseRenderer, then there are a few issues that may be causing this. Two of the most prevalent are:
- Missing pyyaml dependency
https://github.com/encode/django-rest-framework/issues/6300
When attempting to use the rest_framework.schemasget_schema_view, Django Rest Framework requirespyyaml
Solution #1:
Install pyyamlpip install pyyaml
Solution #2:
Use a version of Django Rest Framework that doesn’t require pyyaml for schemapip install djangorestframework==3.8.0 - Invalid renderers settings
When setting renderer_classes it’s important to use the api_settings from rest_framework instead of the DEFAULT_RENDERER_CLASSES from your REST_FRAMEWORK Django settings.
from rest_framework.settings import api_settings
renderer_classes = tuple(api_settings.DEFAULT_RENDERER_CLASSES) + (CSVRenderer,)