InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How to filter items in the Model? |
|
Answer» ModelName.objects.filter(field_name=”TERM”) |
|
| 2. |
How to view all items in the Model? |
|
Answer» ModelName.objects.all() |
|
| 3. |
What’s the significance of the settings.py file? |
|
Answer» As the NAME SUGGESTS this file stores the configurations or settings of our Django project, like database configuration, backend engines, middlewares, INSTALLED applications, main URL configurations, STATIC file addresses, templating engines, main URL configurations, security keys, allowed hosts, and MUCH more. |
|
| 4. |
What is django.shortcuts.render function? |
|
Answer» When a view function returns a webpage as HttpResponse instead of a simple string, we use render(). Render function is a shortcut function that lets the developer easily pass the data dictionary with the template. This function then combines the template with a data dictionary via templating engine. FINALLY, this render() returns as HttpResponse with the rendered text, which is the data returned by MODELS. Thus, Django render() bypasses most of the developer’s work and lets him use different template engines. |
|
| 5. |
What is context in the Django? |
|
Answer» Context is a dictionary mapping template variable NAME GIVEN to Python objects in Django. This is the general name, but you can GIVE any other name of your choice if you WANT. |
|
| 6. |
What’s the use of Middleware in Django? |
|
Answer» Middleware is something that executes between the request and response. In simple words, you can SAY it ACTS as a bridge between the request and response. Similarly In Django when a request is made it MOVES through MIDDLEWARES to views and DATA is passed through middleware as a response. |
|
| 7. |
What's the use of a session framework? |
|
Answer» USING the session framework, you can easily store and retrieve arbitrary DATA BASED on the pre-site-visitors. It stores data on the server-side and takes care of the process of sending and RECEIVING COOKIES. These cookies just consist of a session ID, not the actual data itself unless you explicitly use a cookie-based backend. |
|
| 8. |
What databases are supported by Django? |
|
Answer» PostgreSQL and MYSQL, SQLite and Oracle. APART from these, DJANGO also supports databases such as ODBC, Microsoft SQL Server, IBM DB2, SAP SQL Anywhere, and Firebird using third-party packages. Note: OFFICIALLY Django doesn’t support any no-SQL databases. |
|
| 9. |
Explain Django Response lifecycle? |
|
Answer» Whenever a request is MADE to a web page, Django creates an HttpRequest object that contains METADATA about the request. After that Django loads the particular view, PASSING the HttpRequest as the first argument to the view function. Each view will be returning an HttpResponse object.
|
|
| 10. |
How to configure static files? |
|
Answer» Ensure that django.contrib.staticfiles is added to your INSTALLED_APPS In your settings file. define STATIC_URL for ex. STATIC_URL = '/static/' In your Django templates, use the static template tag to create the URL for the GIVEN relative path using the CONFIGURED STATICFILES_STORAGE. {% load static %}<IMG src="{% static 'my_sample/abcxy.jpg' %}" alt="ABC image">Store your static files in a folder called static in your app. For example my_sample/static/my_sample/abcxy.jpg |
|
| 11. |
Explain user authentication in Django? |
|
Answer» Django comes with a built-in user authentication system, which HANDLES objects LIKE users, groups, user-permissions, and few cookie-based user sessions. Django User authentication not only authenticates the user but ALSO authorizes him.
|
|
| 12. |
Explain the caching strategies in the Django? |
||||||||||
|
Answer» Caching refers to the technique of storing the output results when they are processed initially so that next time when the same results are fetched again, instead of processing again those already stored results can be USED, which leads to faster accessing as well us LESS resource utilization. DJANGO provides us with a robust cache system that is able to STORE dynamic web pages so that these pages don’t need to be evaluated again for each request.
|
|||||||||||
| 13. |
What are Django Signals? |
||||||||||||
|
Answer» Whenever there is a modification in a model, we may need to TRIGGER some actions. List of built-in signals in the models:
|
|||||||||||||