Q. Which function is used to render templates in Django?

  • (A) load_template()
  • (B) render_template()
  • (C) template()
  • (D) render()
πŸ’¬ Discuss
βœ… Correct Answer: (D) render()
Explanation: `render()` combines a template with a context dictionary and returns an HttpResponse.

Q. How do you define a custom command in Django?

  • (A) Add to models.py
  • (B) Create a script in root folder
  • (C) Inside app/management/commands
  • (D) Inside app/scripts
πŸ’¬ Discuss
βœ… Correct Answer: (C) Inside app/management/commands
Explanation: Custom commands are defined in the `management/commands` directory of an app.

Q. Which field is ideal for storing long text content in Django?

  • (A) CharField
  • (B) TextField
  • (C) StringField
  • (D) ParagraphField
πŸ’¬ Discuss
βœ… Correct Answer: (B) TextField
Explanation: `TextField` is used for large text content in Django.

Q. Which class is used to validate Django forms?

  • (A) FormValidator
  • (B) BaseForm
  • (C) Form
  • (D) ModelFormValidator
πŸ’¬ Discuss
βœ… Correct Answer: (C) Form
Explanation: `Form` is the base class used for validating and handling forms in Django.

Q. Which directive in Django templates is used to load static files?

  • (A) {% media %}
  • (B) {% include_static %}
  • (C) {% load static %}
  • (D) {% get_static %}
πŸ’¬ Discuss
βœ… Correct Answer: (C) {% load static %}
Explanation: `{% load static %}` is used to load static files in Django templates.

Q. Which function is used to hash passwords in Django?

  • (A) encrypt_password()
  • (B) hash_password()
  • (C) make_password()
  • (D) secure_password()
πŸ’¬ Discuss
βœ… Correct Answer: (C) make_password()
Explanation: `make_password()` is used to hash a plain text password in Django.

Q. Which command is used to apply migrations to the database?

  • (A) python manage.py sync
  • (B) python manage.py dbmigrate
  • (C) python manage.py migrate
  • (D) python manage.py update
πŸ’¬ Discuss
βœ… Correct Answer: (C) python manage.py migrate
Explanation: `migrate` applies the migrations to the database.

Q. Which of the following is used for debugging SQL queries in Django?

  • (A) query_log()
  • (B) connection.queries
  • (C) print_sql()
  • (D) sql_log()
πŸ’¬ Discuss
βœ… Correct Answer: (B) connection.queries
Explanation: `connection.queries` shows the list of all SQL queries run in a request/response cycle.

Q. What is the default primary key field in Django models?

  • (A) CharField
  • (B) AutoField
  • (C) UUIDField
  • (D) IDField
πŸ’¬ Discuss
βœ… Correct Answer: (B) AutoField
Explanation: `AutoField` is the default primary key if none is specified.

Q. Which management command lists all of the URLs in a Django project?

  • (A) python manage.py showurls
  • (B) python manage.py listurls
  • (C) python manage.py show_urls
  • (D) Not available by default
πŸ’¬ Discuss
βœ… Correct Answer: (D) Not available by default
Explanation: Django does not provide a built-in command to list all URLs; you can install third-party packages for this.