0% found this document useful (0 votes)
31 views

Django

The document discusses various Django concepts like Django Rest Framework, API types, authentication vs authorization, cookies vs sessions, Django admin, model relations, permissions, serialization, middleware, status codes, deployment tools, creating apps and projects, file structure, MVC vs MVT patterns, values vs values_list, signals, mixins, and ORM methods like get vs filter.

Uploaded by

janhavi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Django

The document discusses various Django concepts like Django Rest Framework, API types, authentication vs authorization, cookies vs sessions, Django admin, model relations, permissions, serialization, middleware, status codes, deployment tools, creating apps and projects, file structure, MVC vs MVT patterns, values vs values_list, signals, mixins, and ORM methods like get vs filter.

Uploaded by

janhavi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1) Why we need to go for Django Rest Framework as Django

framework is already available

Django : It provide features for standard web app

Django Rest Framework: It provide features to build standard REST API.

DRF is help to write less code and more reusebility of class when
compared to Django

2) What are the types of API’s?

A. function based apiview


B. Class based apiview
C. Generic apiview
D. Concrete view

3) What is the difference between Authorization and Authentication?

Authentication is the process of verifying with the user credentials


Authorization gives those users permission to access a resource.

Authentication Authorization
What does it do? Verifies credentials Grants or denies
permissions
How does it Through passwords, Through settings
work? biometrics, one-time pins, or maintained by security
apps teams
Is it visible to the Yes No
user?
It is changeable Partially No
by the user?
How does data Through ID tokens Through access tokens
move?
4)What is the difference between Cookie and Session?Where do you
use these in your project?

Cookies are stored in client-side that contain user information


Sessions are stored in server-side that contain user information
Cookie is not dependent on session, but Session is dependent
on Cookie.
Cookie expires depending on the lifetime you set for it, while
a Session ends when a user closes his/her browser

4) What is admin in Django?What is the necessity and advantage of


admin?

Django has inbuilt admin feature,with this we will do authenticate user


and also manage model data.
create a superuser login, register models with the admin, customize how
our models are viewed in the admin, add and edit model data, and learn
how to manage users in the admin.
Process of creating superuser
A. pip install createsuperuser
-enter username
-enter email
-enter password
-reenter password
Say y
Superuser created successfully

5) We have two tables with foreign key relation.How do you get related
data from child table based on parent table Value(id)

Employee.objects.get(created_by=created_by)

6) How do you secure your code?

A. cross site request forgery is used to secure form which was filled by
user that is send to server side
B. To keep views secure we use csrf_exempt
C. If someone access to the csrftoken cookie in the middle then it will
cause hacked to avoid this we use HTTP or HTTPS protocols
To set up HTTP these point add to settings.py
Csrf_cookie_secure=True
Session_cookie_secure=True
D. Django itself has Django administration secure,before you deploy
your application, you want to change admin path url .
We will use django-admin-honeypot and this will notify you if someone
try to access
E. content security plolity your application is too large , contains a lot of
third party code

7) How to write custom permissions?

For custom permission we use


Has_permission(self,request,view)
Has_object_permission(self,request,view,object)
The method return true if the request granted access and false
otherwise

8) What is the recent version of django

We used 1.10 version in my project and latest version is 3.0.5

9) How to do update a django

Py -m pip install --upgrade django

10) What are django package?

We install packages in django by using pip install package_name


(i.e,mysqlclient ,return , request,HTTp Response etc)

11) What are the types of serializes? Which one is best and why?

Serializer allow complex data such as querysets and model instances to


be converted to python native datatypes then it can be easily rendered
into json,xml.
We used mostly two types of serializes
1. Modelserializer
2. Hyperlinkmodelserializer

Modelserializer: It is aslo same normal serializer except


It will generate fileds automatically based on models
Hyperlinkmodelserializer:
It is also same as modelserializer class except it uses hyperlink to
represent relationship,rather than the primary key
By default the serializer will include a url field instead of a primary key
field.

12) Explain the flow of django?

Here, a user requests for a resource to the Django, Django works as a


controller and check to the available resource in URL.

If URL maps, a view is called that interact with model and template, it
renders a template.

Django responds back to the user and sends a template as a response.


13) How to install commands in Django?

In Django, we use pip install command for installation

14) What are middle wares ?Why middle wares are used?Have you
created any custom middle wares?

In django, middleware is a lightweight plugin that process during request


and response execution.It is used to perform a function in the
application,the function may be session, authenticate ,security,csrf
protection etc
Django provides various inbuilt middleware and also possible to write
our own middleware in the settings.py
Middleware examples:
Security Middleware is used to maintain the security of the application.

15) What are the status code available in DRF

Status code 200 -- ok


201 - created
202 - accepted
301 - permanent redirect
302 - temporary redirect
400 - bad request
404 - not found
410 - gone
500 - internal server error
503 - service unavailable

16) Which aws tools you have used for deployment?

Jenkins tools for deployment in the amazon ec2 virtual machine

17) Have you written any Jenkins jobs?

No
These steps to follow to create jenkins job
1. login to jenkins
2. Create new item
3. Enter item details
4. Enter project details
5. Enter repository url
6. Tweak the settings
7. Save the project
8. Build the source code
9. Check the status
10. see the console output

18) What is the necessity of creating App ? is it not possible to


develop using project directly?

 Django apps are reusable i.e. a Django app can be used with
multiple projects.
 We have loosely coupled i.e. almost independent components
 Multiple developers can work on different components
 Debugging and code organization is easy. Django has an excellent
debugger tool.
 It also provide pre-installed apps

19) How we manage two different databases simultaneously in


Django project?

Yes we can use two database in a project

20) How we connect sql server to django project?

1. install the database which we want to use using pip install database
name
2. Edit the settings.py in root directory
Database ={
Engine :
Name :
Host :
Username :
Password :
}
It contains dictionary(key-value) format.

21) Explain the procedure to create app in Django ?

1. check the pip version = pip --version


2. Upgrade the pip = py -m pip install --upgrade pip
3. Install the virtual environment= pip install virtualenvwrapper-win
4. Create virtuan env= mkvirtualenv myapp1
5. Install django = pip install django
6. Check django version = django-admin --version
Create django project
7. Mkdir project1
8. Cd project1
9. Django-admin startproject project1
10. Python manage.py startapp application_name
22) Explain the file structure of a typical Django project?

Ans. A Django project is a collection of web-applications that coordinate


together to serve the request of the user.
These applications have one assigned feature and shall do only that.
A typical Django project consists of these four files:
 manage.py
 settings.py
 __init__.py
 urls.py
 wsgi.py
The last four files are inside a directory, which is at the same level of
manage.py.
Here the structure is very logical, and the names of these files and their
purpose should remain intact.
manage.py is the command-line utility of your Django project and this
file is used to control your Django project on the server or even to begin
one.
When Django server is started, the manage.py file searches
for settings.py file, which contains information of all the applications
installed in the project, middleware used, database connections and
path to the main urls config.
The urls.py file is like a map of your whole web-project, this file
examines URL and calls the right view function or transports the URL to
another application-specific urls-config file.
This is like the main URL linker and any app installed in the settings.py
which you wish to be searched by the URL should have a link here.
The __init__.py file is an empty file which is there to make the python
interpreter understand that the directory consisting settings.py is a
module/ package.
The wsgi.py file is for the server format WSGI, which Django supports
natively. We can customize that for other server formats.
23) Explain difference between MVC and MVT

MVC : Model-view-controller. It separate the business logic and model


data.
MVT : Model-view-template. Django will act as a controller part.

24) Explain difference between values and values_list

Values : When we want to return specific column in that case we use


values. It return a dictionary format
Values_list : It return a tuples format when iterate over.

25) What are the roles of receiver and sender in signals?

 The receiver is the callback function which will be connected to a signal


 The sender specifies a particular sender to receive signals from

26) Explain Mixins in Django ?

A mixin is a special kind of multiple inheritance. There are two main


situations where mixins are used: to provide a lot of optional features
for a class and to use one particular feature in a lot of different classes

27) Difference between get and filter in ORM?

Get: To get the data of particular row


Post : To get matching result from a database,its return a list of object.

28) Difference between Primary Key and Unique Key

Primary Key Unique Key


Unique identifier for rows of a Unique identifier for rows of a table
table when primary key is not present
Cannot be NULL Can be NULL
Only one primary key can be Multiple Unique Keys can be present in a
present in a table table
Primary Key Unique Key
present in a table present in a table
Selection using primary key Selection using unique key creates non-
creates clustered index clustered index

You might also like