Django Flashcards

1
Q

What are models in Django?

A

A model is a Python class in Django that is derived from the django.db.models.Model class. A model is used in Django to represent a table in a database. It is used to interact with and get results from the database tables of our application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are templates in Django or Django template language?

A

Templates are an integral part of the Django MVT architecture. They generally comprise HTML, CSS, and js in which dynamic variables and information are embedded with the help of views. Some constructs are recognized and interpreted by the template engine. The main ones are variables and tags.

A template is rendered with a context. Rendering just replaces variables with their values, present in the context, and processes tags. Everything else remains as it is.

The syntax of the Django template language includes the following four constructs :

Variables
Tags
Filters
Comments
To read more about templates you can refer to this: https://docs.djangoproject.com/en/3.1/topics/templates/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are views in Django?

A

A view function, or “view” for short, is simply a Python function that takes a web request and returns a web response. This response can be HTML contents of a web page, or a redirect, or a 404 error, or an XML document, or an image, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define static files and explain their uses?

A

Websites generally need to serve additional files such as images. Javascript or CSS. In Django, these files are referred to as “static files”, Apart from that Django provides django.contrib.staticfiles to manage these static files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Django Rest Framework(DRF)?

A

Django Rest Framework is an open-source framework based upon Django which lets you create RESTful APIs rapidly. DRF is especially useful if we have an existing Django web application and we wish to quickly generate an API for it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is django-admin and manage.py and explain its commands?

A

django-admin is Django’s command-line utility for administrative tasks. In addition to this, a manage.py file is also automatically created in each Django project. Not only does it perform the same purpose as the django-admin but it also sets the DJANGO_SETTINGS_MODULE environment variable to point to the project’s settings.py file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Django URLs?

A
URLs are one of the most important parts of a web application and Django provides you with an elegant way to design your own custom URLs with help of its module known as URLconf (URL Configuration). The basic functionality of this python module is to 
You can design your own URLs in Django in the way you like and then map them to the python function (View function). These URLs can be static as well as dynamic. These URLs as present in the urls.py where they are matched with the equivalent view function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between a project and an app in Django?

A
In simple words Project is the entire Django application and an app is a module inside the project that deals with one specific use case. 
For eg, payment system(app) in the eCommerce app(Project).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain user authentication in Django?

A

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.

The system consists and operates on these objects:

Users
Permissions
Groups
Password Hashing System
Forms Validation
A pluggable backend system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain Django Response lifecycle?

A

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.
On the big picture following steps occur when a request is received by Django:

First of the Django settings.py file is loaded which also contain various middleware classes (MIDDLEWARES)

The middlewares are also executed in the order in which they are mentioned in the MIDDLEWAREST

From here on the request is now moved to the URL Router, who simply gets the URL path from the request and tries to map with our given URL paths in the urls.py.

As soon as it has mapped, it will call the equivalent view function, from where an equivalent response is generated

The response also passes through the response middlewares and send back to the client/browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What databases are supported by Django?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s the significance of the settings.py file?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the use of the include function in the urls.py file in Django?

A

As in Django there can be many apps, each app may have some URLs that it responds to. Rather than registering all URLs for all apps in a single urls.py file, each app maintains its own urls.py file, and in the project’s urls.py file we use each individual urls.py file of each app by using the include function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Mention some disadvantages of Django.

A

Django has the following disadvantages:

Django’ modules are bulky.
It is completely based on Django ORM.
Components are deployed together.
We must know the full system to work with it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly