Django Basic Interview Questions and Answers
1. What is Django?
Django is a high-level Python web framework that enables rapid development of secure and maintainable
websites. It follows the MTV (Model-Template-View) architecture.
2. Key Features of Django?
Includes built-in admin, ORM, routing, security features, and follows DRY principles.
3. Difference between Project and App?
Project is the entire web application; App is a module within the project.
4. What is MTV architecture?
Model handles data, Template handles presentation, View connects both.
5. What is a Model?
A Python class representing a database table using Django ORM.
6. How to create a project?
Use command: django-admin startproject projectname
7. How to create an app?
Use command: python manage.py startapp appname
8. Use of settings.py?
Holds configuration like DB settings, middleware, and installed apps.
9. Use of urls.py?
Maps URLs to views for routing user requests.
10. What is a view?
Python function or class that takes a request and returns a response.
11. What are migrations?
They update the database schema to match model changes.
12. What is Django admin?
A built-in tool to manage models via a web interface.
13. How to register a model in admin?
In admin.py: admin.site.register(ModelName)
14. What is a template?
HTML file with dynamic placeholders using Django template language.
15. What is context?
Data dictionary passed from views to templates.
16. What is a form?
Used to handle user input via Django's Forms or ModelForms.
17. What is ModelForm?
Auto-generates form fields from model definition.
18. What is middleware?
A layer that processes request and response (e.g., authentication, security).
19. What is manage.py?
Utility script to run commands like runserver, migrate, etc.
20. Connecting to a database?
Edit DATABASES in settings.py to configure SQLite, MySQL, etc.
21. How to use static files?
Place in static/, and load in templates using {% static 'file.css' %}.
22. Types of views?
Function-based and Class-based views.
23. Use of __str__()?
Returns human-readable object name for admin or debugging.
24. What is CSRF?
Security measure to protect forms using {% csrf_token %}.
25. How to create a superuser?
Command: python manage.py createsuperuser