Django Interview Question
Django Interview Question
Django’s Models and Views are present on the client machine and only
templates return to the client, which are essentially HTML, CSS code and
contains the required data from the models.
These components are totally different from each other and therefore,
front-end developers and backend developers can work simultaneously on
the project as these two parts changing will have little to no effect on each
other when changed.
RESTful APIs are perfect for web applications since they use low bandwidth
and are designed such that they work well with communications over the
Internet like GET, POST, PUT, etc.
Q.11 Explain the importance of settings.py file and what data/ settings it
contains.
Ans. When Django server starts, it first looks for settings.py. As the name
settings, it is the main settings file of your web application.
Everything inside your Django project like databases, backend engines,
middlewares, installed applications, main URL configurations, static file
addresses, templating engines, allowed hosts and servers and security key
stores in this file as a list or dictionary.
So, when your Django server starts it executes settings.py file and then
loads particular engines and databases so that when a request is given it
can serve the same quickly.
Q.16 What are View functions? Can we directly import a function in URL?
Ans. The View is the middle component in Django that receives data from
the Django models and pass the same to the Templates.
Every application in Django comes with views.py file, this file contains the
View functions.
The View functions are functions which receive an argument and they
return a browser-renderable format or a redirect.
For that, we have to first import the view function in the urls.py file and
then add the path/ URL which browser should request to call that View
function.
Here as you can see that we imported all the functions from our View
module which is in the same folder.
We added the URL in the urlpatterns list (red box). When the ‘dataflair/’
gets searched in the yellow box, we have called a function named index.