Below is the list of Django interview questions and answers, This will help you in cracking any Django interview question. If you read all the Django Interview Questions then you most likely to impress the interviewer
1. What do you mean by Django?
Django is a high-level Python Web programming framework that is used for rapid and clean development.
Django is a server-side web application open source development framework written in Python.
2. What does Django mean?
Django is named after Django Reinhardt, a wanderer jazz guitarist from the 1930s to mid 1950s who is known as perhaps the best guitarist ever.
3. What is the architectural pattern of Django?
Django follows Model-View Template (MVT) architectural pattern. MVT is a slight variation of the Model View Controller (MVC) architecture.
4. Explain the architecture layers of Django ?
Django is based on MVT architecture. It contains the following layers:
- Models: It describes the database schema and data structure.
- Views: The view layer is a user interface. It controls what a user sees, the view retrieves data from appropriate models and execute any calculation made to the data and pass it to the template.
- Templates: It determines how the user sees it. It describes how the data received from the views should be changed or formatted for display on the page.
- Controller: Controller is the heart of the system. It handles requests and responses, setting up database connections and loading add-ons. It specifies the Django framework and URL parsing.
5. Who manages Django?
Ans: Django web framework is managed and maintained by an independent and non-profit organization named Django Software Foundation (DSF).
6. Explain the key characteristic of Django web framework?
Ans: The characteristic of Django web framework are:
- Admin Interface (CRUD)
- Form handling
- Session, user management, role-based permissions
- Object-relational mapping (ORM)
- Testing Framework
- Fantastic Documentation
7. What is Django Admin Interface?
Django comes with a fully customizable in-built admin interface, which lets us see and make changes to all the data in the database of registered apps and models. To use a database table with the admin interface, we need to register the model in the admin.py file.
8. Explain advantages of Django web development?
- It encourages you to separate code modules into coherent gatherings to make it adaptable to change.
- It gives auto-created web administrator to make website organization simple.
- It gives pre-bundled API to normal client errands.
- It gives layout framework to characterize HTML format for your web page to stay away from code duplication.
- It empowers you to characterize what URL is really going after given capacity.
- It empowers you to isolate business rationale from the HTML.
9. How do you create a project in Django?
Ans: To start a project in Django, use the command $django-admin.py and then use the following command:
Project _init_.py manage.py settings.py urls.py
10. Inheritance styles in Django?
There are mainly three inheritance styles in Django:
Abstract base classes: This style is used when you only want parent?s class to hold information that you don’t want to type out for each child model.
Multi-table Inheritance: This style is used if you are sub-classing an existing model and need each model to have its own database table.
Proxy models: This style is used, if you only want to modify the Python level behavior of the model, without changing the model’s fields.
11. Explain the database setup steps in Djanago?
To set up a database in Django, you can use the command edit mysite/setting.py.
By default, Django uses SQLite database. It is easy for Django users because it doesn’t require any other type of installation. In the case of other database you have to the following keys in the DATABASE ‘default’ item to match your database connection settings.
- Engines: you can change database by using ‘django.db.backends.sqlite3’ , ‘django.db.backeneds.mysql’, ‘django.db.backends.postgresql_psycopg2’, ‘django.db.backends.oracle’ and so on
- Name: The name of your database. In the case if you are using SQLite as your database, in that case database will be a file on your computer, Name should be a full absolute path, including file name of that file.
Note: You have to add setting likes setting like Password, Host, User, etc. in your database, if you are not choosing SQLite as your database.
12. What does Django templates contain?
A Django template is only a text file. It is used to create any text-based format like XML, CSV, HTML, etc. A template contains variables that get replaced with values when the template is evaluated and tags (%tag%) that controls the logic of the template.
13. Do you thing Django is a CMS (content management system)?
No, Django is not a CMS. It is a Web framework and a programming tool that is used to build websites.
14. Explain the session framework in Django?
The session framework provides you to store and retrieve arbitrary data on a per-site visitor basis. It keeps data on the server side and abstracts the receiving and sending of cookies. Session can be implemented through a piece of middleware.
15. How do you set up static files in Django?
There are three steps required to set up static files in Django:
- Set STATIC_ROOT in settings.py
- run manage.py collectsatic
- set up a Static Files entry on the PythonAnywhere web tab
16. How do you use file based sessions in Django?
We need to set the SESSION_ENGINE settings to “django.contrib.sessions.backends.file” to enable file based session.
17. What are the usage of middlewares in Django?
few usage of middlewares in Django as follows:
- Session management,
- Use authentication
- Cross-site request forgery protection
- Content Gzipping, etc.
18. What is the use of Django field class types?
The Use of Django field class type as :
The database column type.
The default HTML widget to avail while rendering a form field.
The minimal validation requirements used in Django admin.
Automatic generated forms.
19. what command you use to start Django’s built-in development server?
20. Given a model named ‘User’ that contains a DateTime field named ‘last_login’, how do you query for users that have never logged in?
User.objects.filter( last_login__isnull=True )
21. What does the Django command
manage.py shell do?
This Starts a Python command prompt with your Django environment pre-loaded.
22. Assuming you have imported the proper Django model file, how do you add a ‘User’ model to the Django admin?
admin.site.register( User )
23. What is the Django command to start a new app named ‘users’ in an existing project?
manage.py startapp users
24. What does a urls.py file do in Django?
It contains URL matching patterns and their corresponding view methods.
25. Tell the Command to run Django’s development server on port 8080 on IP address 22.214.171.124?
manage.py runserver 126.96.36.199:8080
26. Django is bases on which programming language?
27. Once you make a new ‘app’ in your existing Django project, how you set Django to notice it?
In settings.py, add the new app to the INSTALLED_APPS variable.