Python | Django | Advanced Features

Last Updated :
Discuss
Comments

Question 1

What is the main purpose of a middleware in Django?

  • To define model-level validations

  • To process request or response globally before or after the view

  • To handle database migrations

  • To render HTML templates

Question 2

Why might a developer use caching in Django?

  • To store user credentials permanently

  • To compress media files automatically

  • To save the results of expensive computations so that future requests are faster

  • To bypass authentication

Question 3

In Django’s ORM what does the function aggregate() do on a queryset?

  • Adds a new field to every object

  • Deletes duplicate records

  • Filters the queryset based on conditions

  • Returns a summary result (like sum, count, average) over the entire queryset

Question 4

What is the role of annotate() in Django ORM?

  • It executes raw SQL queries
    C)
    D)

  • It modifies model definitions

  • It resets the database

  • It computes a value for each object in the queryset

Question 5

In Django, what is a signal used for?

  • To perform asynchronous database backups

  • To handle URL routing

  • To allow certain actions (like save, delete) to trigger custom behavior elsewhere in the code

  • To render serializers automatically

Question 6

If a heavy database query result is unlikely to change often, what is the benefit of using Django caching for that data?

  • It ensures data never changes

  • It provides faster responses by avoiding repeated queries

  • It automatically cleans the database

  • It encrypts the data

Question 7

Suppose you want total sales amount across all orders in a queryset. Which would you use in Django ORM?

  • aggregate()

  • annotate()

  • filter()

  • order_by()

Question 8

Suppose you want, for each customer, the number of orders placed by them. Which Django ORM method best fits this scenario?

  • aggregate()

  • get()

  • delete()

  • annotate()

Tags:

There are 8 questions to complete.

Take a part in the ongoing discussion