โ† All Django Flashcard Decks

Django REST Framework Flashcards

6 cards from real Django practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Django REST Framework flashcards as text
  1. How does DRF's `ModelSerializer` handle the `create()` method by default?

    Answer: It calls Model.objects.create() with the validated data

    ModelSerializer's default create() calls Model.objects.create(**validated_data), which creates and saves the instance in one database operation.

  2. What does `serializer.save()` do in DRF?

    Answer: Calls create() or update() depending on whether an instance was provided

    If the serializer was initialized with an instance=obj argument, save() calls update(); otherwise it calls create() on the validated data.

  3. Which DRF pagination class splits results into pages of a fixed size?

    Answer: PageNumberPagination

    PageNumberPagination splits querysets into pages accessed via a page query parameter, configurable with PAGE_SIZE in DEFAULT_PAGINATION_CLASS settings.

  4. What is the purpose of DRF's `SerializerMethodField`?

    Answer: Adds a read-only field computed by a custom method on the serializer

    SerializerMethodField calls a get_() method on the serializer to compute the field's value, useful for derived or annotated data.

  5. How do you make a DRF API endpoint return XML instead of JSON?

    Answer: Add XMLRenderer to the view's renderer_classes and request Accept: application/xml

    DRF uses content negotiation; adding XMLRenderer to renderer_classes and sending Accept: application/xml in the request returns XML output.

  6. What does DRF's `HyperlinkedModelSerializer` add compared to `ModelSerializer`?

    Answer: Uses URLs instead of primary keys for relationships between resources

    HyperlinkedModelSerializer uses a url field and HyperlinkedRelatedField for relationships, returning full URLs instead of IDs for related objects.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy