15👍
You need to include queryset = Post.objects.all()
in your PostList
view, as well as in PostDetail
.
Every view needs a queryset defined to know what objects to look for. You define the view’s queryset by using the queryset
attribute (as I suggested) or returning a valid queryset from a get_queryset
method.
By the way, you can get rid of the model
attribute in your views as they aren’t used. That’s not the correct way to tell the view what objects to look for.
0👍
Need to just include in views.py and create serializers.py
views.py
from autentication.serializers import TestSerializer
authentication_classes = ()
permission_classes = ()
serializer_class = TestSerializer
serializers.py
from rest_framework import serializers
class TestSerializer(serializers.Serializer):
Note : Python 3.8.x with djangorestframework 3.11.x
- Django.db.utils.OperationalError: near "[]": syntax error
- How do you get Django to make a RESTful call?
- Django-tables2 add button per row
- Django south fresh install –> error: unknown command 'schemamigration'
- TypeError: ‘DoesNotExist’ object is not callable
- Uncaught ReferenceError: django is not defined
- ALLOWED_HOSTS and Django
- {% load static %} and {% load staticfiles %}: which is preferred?
- How do you get Django to make a RESTful call?
- Django – filtering by "certain value or None"
0👍
In my case, I use generics with RetrieveAPIView and my simple mistake
error code
class PizzeriaRetrieveAPIView(generics.RetrieveAPIView):
lookup_field = "id"
querysets = Pizzeria.objects.all()
serializer_class = PizzeriaDetailSerializer
and fixed code, i removed "s" from querysets -> queryset
class PizzeriaRetrieveAPIView(generics.RetrieveAPIView):
lookup_field = "id"
queryset = Pizzeria.objects.all()
serializer_class = PizzeriaDetailSerializer
everything works fine, somethimes we mistake a small changes…
- Django how to set request user in client test
- Add functionality to Django FlatPages without changing the original Django App
- GeoDjango on Windows: Try setting GDAL_LIBRARY_PATH in your settings
- Apache mod_wsgi error: Forbidden You don't have permission to access / on this server