Q. Which model field is used to store date and time in Django?

  • (A) DateField
  • (B) DateTimeField
  • (C) TimeStampField
  • (D) TimeField
πŸ’¬ Discuss
βœ… Correct Answer: (B) DateTimeField
Explanation: `DateTimeField` stores both date and time values.

Q. Which file is required to make a directory a Python package?

  • (A) package.py
  • (B) __init__.py
  • (C) index.py
  • (D) start.py
πŸ’¬ Discuss
βœ… Correct Answer: (B) __init__.py
Explanation: `__init__.py` tells Python to treat the directory as a package.

Q. How can you enable internationalization in Django?

  • (A) Use LocaleMiddleware and enable USE_I18N
  • (B) Set LANGUAGE=True
  • (C) Add translation tags
  • (D) Enable Locales in views
πŸ’¬ Discuss
βœ… Correct Answer: (A) Use LocaleMiddleware and enable USE_I18N
Explanation: Internationalization is enabled by setting `USE_I18N = True` and using `LocaleMiddleware`.

Q. Which of the following is used to define custom model managers?

  • (A) class CustomManager(models.Manager)
  • (B) def manager(self)
  • (C) class ModelHandler
  • (D) def handle(self)
πŸ’¬ Discuss
βœ… Correct Answer: (A) class CustomManager(models.Manager)
Explanation: You can create a custom manager by subclassing `models.Manager`.

Q. What is the use of `blank=True` in Django model fields?

  • (A) Field must be left blank
  • (B) Field value will be hidden
  • (C) Allows field to be blank in forms
  • (D) Field will be ignored
πŸ’¬ Discuss
βœ… Correct Answer: (C) Allows field to be blank in forms
Explanation: `blank=True` allows a field to be optional in forms.

Q. What is the use of `null=True` in Django model fields?

  • (A) Field stores NULL in database if left empty
  • (B) Field cannot be used
  • (C) Field will be automatically set to zero
  • (D) Field is ignored by admin
πŸ’¬ Discuss
βœ… Correct Answer: (A) Field stores NULL in database if left empty
Explanation: `null=True` allows storing NULL in the database for that field.

Q. How can you protect a Django view from CSRF attacks?

  • (A) By adding {% csrf_protect %} in template
  • (B) By using csrf_token in form and CsrfViewMiddleware
  • (C) By hashing the form data
  • (D) By encoding URLs
πŸ’¬ Discuss
βœ… Correct Answer: (B) By using csrf_token in form and CsrfViewMiddleware
Explanation: Django uses `csrf_token` in forms and `CsrfViewMiddleware` to protect against CSRF attacks.

Q. Which of the following is used to include another template?

  • (A) {% import 'template.html' %}
  • (B) {% extend 'template.html' %}
  • (C) {% include 'template.html' %}
  • (D) {% insert 'template.html' %}
πŸ’¬ Discuss
βœ… Correct Answer: (C) {% include 'template.html' %}
Explanation: `{% include %}` is used to include another template inside a template.

Q. Which HTTP status code is returned by default when `HttpResponseForbidden` is used?

  • (A) 404
  • (B) 403
  • (C) 500
  • (D) 401
πŸ’¬ Discuss
βœ… Correct Answer: (B) 403
Explanation: `HttpResponseForbidden` returns a 403 Forbidden status code.

Q. Which field in Django automatically updates the timestamp when a record is modified?

  • (A) auto_now
  • (B) auto_now_add
  • (C) auto_update
  • (D) timestamp_update
πŸ’¬ Discuss
βœ… Correct Answer: (A) auto_now
Explanation: `auto_now=True` updates the field with the current timestamp every time the model is saved.