Q. Which of these is a valid middleware component?

  • (A) django.middleware.cache.UpdateCacheMiddleware
  • (B) django.middleware.UpdateCache
  • (C) django.middleware.cache.Middleware
  • (D) django.middleware.Cache
πŸ’¬ Discuss
βœ… Correct Answer: (A) django.middleware.cache.UpdateCacheMiddleware
Explanation: UpdateCacheMiddleware is a standard middleware for caching in Django.

Q. Which view is best for showing object detail using a primary key?

  • (A) TemplateView
  • (B) ListView
  • (C) DetailView
  • (D) ModelView
πŸ’¬ Discuss
βœ… Correct Answer: (C) DetailView
Explanation: DetailView displays a single object based on its primary key or slug.

Q. Which template tag is used to load a custom template filter?

  • (A) use
  • (B) load
  • (C) require
  • (D) import
πŸ’¬ Discuss
βœ… Correct Answer: (B) load
Explanation: The load tag is used to include custom template tags and filters.

Q. What is the output of str() method in a Django model?

  • (A) It returns the model's primary key
  • (B) It returns the model class name
  • (C) It returns a string representation of the model instance
  • (D) It returns the ID of the model
πŸ’¬ Discuss
βœ… Correct Answer: (C) It returns a string representation of the model instance
Explanation: The str method returns a human-readable representation of a model instance.

Q. Which file lists installed Django apps?

  • (A) urls.py
  • (B) views.py
  • (C) settings.py
  • (D) models.py
πŸ’¬ Discuss
βœ… Correct Answer: (C) settings.py
Explanation: settings.py contains the INSTALLED_APPS list.

Q. Which method retrieves all objects from a Django model?

  • (A) get_all()
  • (B) fetch_all()
  • (C) all()
  • (D) objects()
πŸ’¬ Discuss
βœ… Correct Answer: (C) all()
Explanation: The all() method returns all records for a model.

Q. Which signal is triggered after a model is saved?

  • (A) pre_save
  • (B) post_update
  • (C) post_save
  • (D) model_saved
πŸ’¬ Discuss
βœ… Correct Answer: (C) post_save
Explanation: post_save is triggered after a model’s save() method completes.

Q. Which Django component is responsible for URL routing?

  • (A) settings.py
  • (B) apps.py
  • (C) urls.py
  • (D) views.py
πŸ’¬ Discuss
βœ… Correct Answer: (C) urls.py
Explanation: urls.py contains URL patterns and routes them to views.

Q. Which model field is suitable for a fixed set of choices?

  • (A) CharField with max_length
  • (B) ChoiceField
  • (C) CharField with choices
  • (D) StringField
πŸ’¬ Discuss
βœ… Correct Answer: (C) CharField with choices
Explanation: CharField with the choices attribute is used for predefined values.

Q. Which field type should you use for boolean values?

  • (A) BooleanField
  • (B) CharField
  • (C) SmallIntegerField
  • (D) TextField
πŸ’¬ Discuss
βœ… Correct Answer: (A) BooleanField
Explanation: BooleanField is used to store True or False values.