Summary of Django's must-have interview questions

The article is transferred from
https://blog.csdn.net/weixin_43063753/article/details/85559540

Contents
insert image description here
Welcome to follow
1 List the common request methods in Http requests
2 Talk about your understanding of the HTTP protocol. 1.1 Long connection
3 Brief description of MVC mode and MVT mode
4 Brief description of Django request life cycle
5 Brief description of what is FBV and CBV
6 Talk about your understanding of ORM
7 Rest_framework authentication component process
8 What is middleware and a brief description of it Function
9 django middleware life cycle
10 how to write native SQL in django
11 how to use django orm to create data in batches

12 The difference between the command migrate and makemigrations
14 What is the way of common view response?
15 Classification of Common Status Codes in HTTP Responses
16 What is the Route Matching Principle?
17 What are the types of cache systems
? 18 What is the common way to solve cross-domain?
19 What is the function of the signal?

20 Django's Model inheritance has several forms, what
are they ? How to read and save the session in Django, and what is the operating mechanism of the entire session Affect 26 How does Django handle cross-domain requests 27 Two major characteristics of query sets? What is lazy execution 28 What are the list filters returned by the query set 29 How to get all the urls registered in django urlpatterns? 30 What is the use of include in the django routing system? 31 What is the difference between the path in django2.0 and the url in django1.xx? 32 What is the role of name and namespace in urlpatterns? How do you use it? 34 How to set a primary key for a field? 35 How to set up a dictionary with enum values? 36 What is the difference between auto_now and auto_now_add in the DateTimeField type? 37 What is the difference between values() and values_list()? 38 What is the difference between selected_related and prefetch_related?

















39 When deleting a foreign key, how to delete the corresponding relationship with it
40 What are the meta information fields in class Meta?
41 How to insert data into a many-to-many associated table? How to delete data? How to update data?
42 In the M2M relationship of django, how to manually generate the third table?
43 In Django, how many ways does the server respond to the client? What are they?
44 In the view function, what are the commonly used validation decorators?
45 How to add caching to a view function?
46 What is the essence of the web framework?
47 Create Django project, Django app, and running commands
48 Implementation mechanism of csrf in django 49
Directory structure of Django App
50 Several ways Django obtains user front-end request data
51 Describe the custom simple_tag
52 What is a cookie, how to obtain it, Setting Cookie
53 What is session, comparison with cookie, setting, obtaining, and clearing session
54 What is CSRF, and how to prevent it
55 The difference between get request and post request
56 How is the table structure of the library management system designed?
57 WSGI / uwsgi / uWSGI distinction
59 Explain blank and null
60 QueryDict and dict difference
61 Tell me about your understanding of restful specifications?
62 Django itself provides runserver, why can't it be used for deployment? 
63 What is the core of Tornado? 
64 How do you implement Django redirection? What status code is used? 
65 How to load initialization data in Django 
66 Briefly describe the (built-in) caching mechanism under Django

Back to top
1 List the common request methods in Http requests
HTTP request methods:
The HTTP/1.1 protocol defines eight methods (sometimes called "actions") to indicate the different operation methods of the resources specified by the Request-URL

Note:
1) The method name is case-sensitive. When the resource targeted by a request does not support the corresponding request method, the server should return status code 405 (Method Not Allowed); when the server does not know or does not support the corresponding request method When requesting a method, a status code of 501 (Not Implemented) should be returned.
2) The HTTP server should at least implement the GET and HEAD/POST methods, and other methods are optional. In addition to the above methods, a specific HTTP server supports extended custom methods.
GET

Make a request to a specific path resource

Note: The GET method should not be used in operations that produce "side effects", such as in WebApplication, one of the reasons is that GET may be randomly accessed by web spiders, etc. Corresponding get request functions in Loadrunner: web_link and web_url

  POST

Submit data to the specified path resource for processing requests (generally used to submit forms or upload files)

Data is contained in the request body, and POST requests may result in the creation of new resources and/or the modification of existing resources. Corresponding POST request function in Loadrunner: web_submit_data, web_submit_form

OPTIONS               

Returns the HTTP request methods supported by the server for a specific resource

Allows the client to view the performance of the server, and can also test the functionality of the server by sending a '*' request to the web server

 HEAD

Ask the server for a response consistent with the GET request, but the response body will not be returned

This method makes it possible to obtain the meta-information contained in the response header without having to transmit the entire response content.

 PUT

The data sent from the client to the server replaces the content of the specified document

 DELETE 

Request the server to delete the specified page

 TRACE

Echo the request received by the server, mainly for testing or diagnosis

 CONNECT

Reserved in the HTTP/1.1 protocol for proxy services that can change connections to pipelines

Go back to top
2 and talk about your understanding of the HTTP protocol. 1.1 Persistent connection
HTTP is an object-oriented protocol belonging to the application layer.
The HTTP protocol works on the client-server architecture. As an HTTP client, the browser sends all requests to the HTTP server, that is, the WEB server, through the URL. The web server sends response information to the client according to the received request.
Based on
the sequence of TCP/IP communication between the two parties, and the steps that need to be processed displayed on the Web page, and so on. A collection of protocols related to the Internet like this is collectively referred to as TCP/IP. The http protocol is an application layer protocol based on the TCP/IP protocol.
Based on the request-response mode
HTTP protocol stipulates that the request is sent from the client, and finally the server responds to the request and returns
stateless storage
. HTTP is a stateless protocol that does not save the state. The HTTP protocol itself does not save the communication state between the request and the response. That is to say, at the HTTP level, the protocol does not persist the sent requests or responses.
Using the HTTP protocol, whenever a new request is sent, a corresponding new response will be generated. The protocol itself does not retain information about all previous request or response messages. This is to process a large number of transactions faster and ensure the scalability of the protocol, and the HTTP protocol is deliberately designed to be so simple. However, with the continuous development of the Web, there are more and more difficult business processes due to statelessness. For example, if a user logs in to a shopping website, even after he jumps to other pages of the site, he needs to be able to continue to log in. For this example, in order to be able to grasp who sent the request, the website needs to save the user's state. Although HTTP/1.1 is a stateless protocol, in order to achieve the desired state-keeping function, Cookie technology is introduced. With cookies and then using the HTTP protocol to communicate, the state can be managed.

Return to top
3 Briefly describe the MVC mode and MVT mode.
The so-called MVC is to divide the Web application into three layers: model (M), controller© and view (V), and they are connected in a plug-in and loosely coupled manner. Together, the model is responsible for the mapping (ORM) of business objects and databases, the view is responsible for interaction with users (pages), and the controller accepts user input to call the model and view to complete the user's request

MTV
Django's MTV mode is essentially the same as MVC, and it also maintains a loosely coupled relationship between components, but the definition is slightly different. Django's MTV is the value:

M stands for Model (Model): Responsible for relational mapping (ORM) of business objects and databases.
T stands for template (Template): responsible for how to display the page to the user (html).
V stands for View (View): Responsible for business logic, and call Model and Template when appropriate.
In addition to the above three layers, a URL distributor is also needed. Its function is to distribute URL page requests to different Views for processing, and then View calls the corresponding Model and Template. The response mode of MTV is as follows:

一般是用户通过浏览器向我们的服务器发起一个请求(request),这个请求回去访问视图函数,(如果不涉及到数据调用,那么这个时候视图函数返回一个模板也就是一个网页给用户),视图函数调用模型,模型去数据库查找数据,然后逐级返回,视图函数把返回的数据填充到模板中空格中,最后返回网页给用户。

Back to top
4 Brief Django request life cycle
is generally that the user initiates a request (request) to our server through the browser, and this request goes back to access the view function (if no data call is involved, then the view function returns a template at this time That is, a web page to the user), the view function calls the model, the model goes to the database to find data, and then returns step by step, the view function fills the returned data into the blanks in the template, and finally returns the web page to the user.
#1.wsgi, encapsulate the request and hand it over to the web framework (Flask, Django)
#2. Middleware, verify the request or add other relevant data to the request object, for example: csrf, request.session -
#3. Routing Matching Matches different view functions according to different urls sent by the browser
#4. View function, the processing of business logic in the view function may involve: orm, templates => rendering-
#5. Middleware, for the response The data is processed.
#6.wsgi, send the content of the response to the browser.

Return to top
For more information, please go to WeChat public reply: django interview questions
insert image description here

There are detailed answers.
For more information, please go to WeChat public reply: django interview questions
For more information, please go to WeChat public reply: django interview questions
For more information, please go to WeChat public reply: django interview questions
———————————— —————
Copyright statement: This article is an original article of CSDN blogger "BigC Brother", following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/weixin_43063753/article/details/85559540

Guess you like

Origin blog.csdn.net/bruce_van/article/details/103841983