53👍
If it’s a function based view, you made need to use an @api_view decorator to display properly. I’ve seen this particular error happen for this exact reason (missing API View declaration in function based views).
from rest_framework.decorators import api_view
# ....
@api_view(['GET', 'POST', ])
def articles(request, format=None):
data= {'articles': Article.objects.all() }
return Response(data, template_name='articles.html')
9👍
In my case just forgot to set @api_view([‘PUT’]) on view function.
So,
.accepted_renderer
The renderer instance that will be used to render the response not set for view.
Set automatically by the APIView or @api_view immediately before the response is returned from the view.
- [Django]-Name '_' is not defined
- [Django]-Using django-admin on windows powershell
- [Django]-Cannot access django app through ip address while accessing it through localhost
4👍
Have you added TemplateHTMLRenderer
in your settings?
http://www.django-rest-framework.org/api-guide/renderers/#setting-the-renderers
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
- [Django]-Using django-admin on windows powershell
1👍
You missed TemplateHTMLRenderer
decorator:
@api_view(('GET',)) @renderer_classes((TemplateHTMLRenderer,)) def articles(request, format=None): data= {'articles': Article.objects.all() } return Response(data, template_name='articles.html')
- [Django]-Django: For Loop to Iterate Form Fields
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
- [Django]-How do I install psycopg2 for Python 3.x?
Source:stackexchange.com