This interview questions database, by the public number: non-undergraduate programmers collate release

What is the request context and application context in Flask?

  • When a request is processed in Flask, a “request context” object is created, and the entire processing of the request takes place in this context object. This ensures that the processing of requests is not disrupted. Flask contains information related to request processing. Flask is also used to store “request context” objects based on a data structure called LocalStack implemented in the Werkzug. local module.
  • Application context is also a context object that can be constructed using the WITH statement. It also implements push, POP, and other methods. The “application context” constructor is similar to the “request context” constructor, with properties such as app, URL_Adapter, and so on. One of the main functions that an “application context” exists is to identify the application in which the request is being made.

Question 2: The use of Django middleware?

Django presets six methods in the middleware. The six methods differ in their phases of execution and interfere with input or output in the following ways:

#1 Initialization: no parameters are required, called once when the server responds to the first request to determine whether the current middleware is enabled

def __init__(a):
    pass

#2. Before processing requests: Called on each request, returning None or an HttpResponse object

def process_response(request):
    pass

#3 called on each request before processing the view, returning None or HttpResopnse objects
def  process_view(request.view_func, view_args, view_kwargs):
    pass

#4 Before processing the template response: called on each request, returning the response object that implements the render method
def peocess_template_response(request, response):
    pass
#5 After processing the response, many responses are called on each request before the response is returned to the browser, returning an HttpResponse object

def process_response(request, response):
    pass

#6 Exception handling: called when the graph throws an exception, on each request, returning an HttpResponse object
def process_exception(request, execption):
    pass
Copy the code

Question 3: What improvements have been made to the data in Django development?

  1. When designing tables, use foreign keys as little as possible because foreign key constraints affect insert and delete performance
  2. Use caching to reduce database access
  3. When setting up a table under the ORM framework, do not use text when you can use vARCHar to determine the length of a field
  4. You can attribute the search frequency to a field and create an index at definition time
  5. Django’s ORM Querysets are already cached
  6. If a page links to the database multiple times, it is best to remove all the required data at once to reduce the number of queries to the database
  7. Queryset.values () if the page only needs one or two fields in the database, use queryset.values ()
  8. Use the with tag in the template tag to cache the Qset query results

Question 4: What are the differences between Django and Tornado?

Django

Django was released as open source in 2005 from an online news Web site.

The core components of the Django framework are:

Object-relational mapping for model creation perfect management interface for end user design first-class URL design designer-friendly template language caching system etc

It encourages rapid development and follows THE MVC design.

Django is BSD compliant. The latest release is Django1.4, which was released on March 23, 2012. The main purpose of Django is to develop database-driven web sites easily and quickly. With its emphasis on code reuse, it’s easy for multiple components to serve the framework in the form of “plug-ins.” Django has many powerful third-party plug-ins, and it’s even easy to develop your own toolkit. This makes Django very extensible. It also emphasizes fast development and the DRY(Do Not RepeatYourself) principle.

Tornado

Tornado is an open source version of the scalable, non-blocking Web server and related tools used by FriendFeed. The Web framework looks a bit like Web.py or Google’s WebApp, but it also includes some useful tools and optimizations to take advantage of a non-blocking server environment.

Tornado is quite different from the mainstream Web server frameworks today, including most Python frameworks: It’s non-blocking and quite fast. Tornado can process thousands of connections per second thanks to its non-blocking approach and use of epoll, which means Tornado is an ideal Web framework for real-time Web services. The main reason we developed the Web server was to handle the real-time functionality of FriendFeed – every active user in the FriendFeed application will have a server connection. (on how to expand the server to handle thousands of client connections.

Question 5: What is restful API? What do you understand?

  • REST: Short for Representational State Transfer. Generally interpreted as “presentation layer state transition”.
  • REST is a design style, not a standard. The form of interaction between the client and the server. What we need to focus on is how do we design
  • REST style network interface.

The characteristics of the REST

  1. The representational. Generally refers to the presentation layer, to represent the object is the resource. For example, when a client accesses a server, the data it retrieves is a resource. Such as text, pictures, audio and video.
  2. Representation: The representation of a resource. TXT format, HTML format, JSON format, and JPG format. The browser determines the location of the resource through the URL, but it needs to be specified in the HTTP request header with Accept and Content-type fields, which describe the representation of the resource.
  3. State transition: The process by which client and server interact. In this process, there must be a transformation of data and state, which is called state transition. GET indicates obtaining resources, POST indicates creating resources, PUT indicates updating resources, and DELETE indicates deleting resources. These four operations are most commonly used in THE HTTP protocol.

A RESTful architecture

  1. Each URL represents a resource;
  2. Some representation layer of this resource is passed between the client and the server;
  3. Through the four HTTP verbs, the client performs operations on the server resources and realizes the state transition of the presentation layer.

Question 6: Follow the topic, recently updated in the public account a magic series of introductory articles

At the age of 27, she started to learn C, C ++ and Python programming languages from scratch. At the age of 29, she wrote 100 example tutorials. At the age of 30, she mastered 10 programming languages

Welcome to follow her public account, search – non-undergraduate programmer