For example, your URLconf might include something like the following entry: url(r'^/users/', ListCreateAPIView.as_view(model=User), name='user-list') Serializer = UserSerializer(queryset, many=True)įor very simple cases you might want to pass through any class attributes using the. # Note the use of `get_queryset()` instead of `self.queryset` Use smaller pagination for HTML representations. class UserList(generics.ListCreateAPIView): from import Userįrom rializers import UserSerializerįrom rest_framework.permissions import IsAdminUserĬlass UserList(generics.ListCreateAPIView):įor more complex cases you might also want to override various methods on the view class. Typically when using the generic views, you'll override the view, and set several class attributes. If the generic views don't suit the needs of your API, you can drop down to using the regular APIView class, or reuse the mixins and base classes used by the generic views to compose your own set of reusable generic views. The generic views provided by REST framework allow you to quickly build API views that map closely to your database models. REST framework takes advantage of this by providing a number of pre-built views that provide for commonly used patterns. One of the key benefits of class based views is the way they allow you to compose bits of reusable behaviour. They take certain common idioms and patterns found in view development and abstract them so that you can quickly write common views of data without having to repeat yourself. were developed as a shortcut for common usage patterns.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |