1. What is Django?
o a) A programming language
o b) A web framework
o c) A database
o d) An IDE
o Answer: b) A web framework
2. Which of the following is true about Django ORM?
o a) It allows raw SQL queries only
o b) It automates SQL generation and execution
o c) It does not support relational databases
o d) It requires external libraries
o Answer: b) It automates SQL generation and execution
3. Which file is the main configuration file in a Django project?
o a) urls.py
o b) settings.py
o c) models.py
o d) views.py
o Answer: b) settings.py
4. Django follows which architectural pattern?
o a) Model-View-Controller (MVC)
o b) Model-Template-View (MTV)
o c) View-Controller-Model (VCM)
o d) None of the above
o Answer: b) Model-Template-View (MTV)
5. Which command is used to start a new Django project?
o a) django-admin createproject
o b) django-admin startproject
o c) python manage.py createproject
o d) django-admin makemigrations
o Answer: b) django-admin startproject
6. Which command is used to apply migrations in Django?
o a) python manage.py migrate
o b) python manage.py runserver
o c) python manage.py startapp
o d) django-admin syncdb
o Answer: a) python manage.py migrate
7. In which of the following is the database model defined in Django?
o a) urls.py
o b) views.py
o c) models.py
o d) settings.py
o Answer: c) models.py
8. How do you define a primary key in a Django model?
o a) By setting the field as primary=True
o b) By setting primary_key=True
o c) Django automatically sets the first field as the primary key
o d) You don’t need to define a primary key
o Answer: b) By setting primary_key=True
9. Which method is used to retrieve all records from a Django model?
o a) all()
o b) get()
o c) filter()
o d) exclude()
o Answer: a) all()
10. How do you run a Django development server?
o a) python manage.py runserver
o b) django-admin runserver
o c) django-admin startproject
o d) python manage.py createsuperuser
o Answer: a) python manage.py runserver
11. Which of the following template engines is used in Django by default?
o a) Jinja2
o b) Mustache
o c) Django Template Language (DTL)
o d) Mako
o Answer: c) Django Template Language (DTL)
12. Which of the following is NOT a valid field type in Django models?
o a) CharField
o b) IntegerField
o c) AutoField
o d) TextboxField
o Answer: d) TextboxField
13. Which decorator is used to restrict access to views in Django?
o a) @login_required
o b) @admin_only
o c) @restrict
o d) @auth_required
o Answer: a) @login_required
14. How are static files typically managed in Django?
o a) By using STATIC_URL and STATICFILES_DIRS in settings.py
o b) By uploading them directly to the server
o c) By storing them in a database
o d) By manually embedding them in HTML
o Answer: a) By using STATIC_URL and STATICFILES_DIRS in settings.py
15. What does Django's makemigrations command do?
o a) Applies changes to the database schema
o b) Prepares migrations based on changes to models
o c) Deletes unused models
o d) Resets the database
o Answer: b) Prepares migrations based on changes to models
16. How do you handle 404 errors in Django?
o a) By defining a custom view
o b) By using Django's built-in error handler
o c) By manually redirecting users
o d) By using a 404.html template
o Answer: a) By defining a custom view
17. What does the ForeignKey field in Django do?
o a) It creates a relationship between two models
o b) It enforces a unique constraint
o c) It stores JSON data
o d) It links to a static file
o Answer: a) It creates a relationship between two models
18. Which command is used to create a superuser in Django?
o a) python manage.py createsuperuser
o b) django-admin createsuperuser
o c) python manage.py startapp
o d) django-admin startproject
o Answer: a) python manage.py createsuperuser
19. Which file is responsible for routing URLs to views in Django?
o a) views.py
o b) urls.py
o c) models.py
o d) admin.py
o Answer: b) urls.py
20. Which of the following allows database transactions in Django?
o a) @transaction.atomic()
o b) @transaction.commit()
o c) @transaction.savepoint()
o d) @transaction.rollback()
o Answer: a) @transaction.atomic()
21. What is the default database used by Django?
o a) PostgreSQL
o b) MySQL
o c) SQLite
o d) Oracle
o Answer: c) SQLite
22. Which of the following is NOT a valid Django management command?
o a) runserver
o b) makemigrations
o c) migrate
o d) execute
o Answer: d) execute
23. Which of these is used for handling forms in Django?
o a) Forms API
o b) HTTP API
o c) Query API
o d) Session API
o Answer: a) Forms API
24. What is the main purpose of Django middleware?
o a) It processes requests and responses globally across the application
o b) It handles database connections
o c) It stores user session data
o d) It controls URL routing
o Answer: a) It processes requests and responses globally across the application
25. Which of the following is used to define URL patterns in Django?
o a) urlpatterns
o b) urlconf
o c) urlhandler
o d) routelist
o Answer: a) urlpatterns
MSQ (Multiple Correct Answers)
26. Which of the following are valid types of fields in Django models?
o a) CharField
o b) DateField
o c) BooleanField
o d) TimeField
o Answers: a) CharField, b) DateField, c) BooleanField, d) TimeField
27. Which of the following are valid HTTP methods used in Django views?
o a) GET
o b) POST
o c) PUT
o d) DELETE
o Answers: a) GET, b) POST, c) PUT, d) DELETE
28. Which commands are used to work with migrations in Django?
o a) makemigrations
o b) migrate
o c) sqlmigrate
o d) showmigrations
o Answers: a) makemigrations, b) migrate, c) sqlmigrate, d) showmigrations
29. Which of the following are valid model relationships in Django?
o a) ForeignKey
o b) OneToOneField
o c) ManyToManyField
o d) IntegerField
o Answers: a) ForeignKey, b) OneToOneField, c) ManyToManyField
30. Which of the following are valid options for ordering query results in Django?
o a) order_by()
o b) filter_by()
o c) exclude()
o d) reverse()
o Answers: a) order_by(), d) reverse()