Deepen the understanding of Django by interview questions
- 2021-07-22 10:39:18
- OfStack
1. What do you know about Django?
#1.Django Is to go in a big and comprehensive direction, and it is best known for its fully automated management background: it only needs to use ORM Do simple object definition, it can automatically generate database structure, as well as a full-featured management background.
#2.Django Built-in ORM It is highly coupled with other modules in the framework.
# Applications must use the Django Built-in ORM Otherwise, you will not be able to enjoy all kinds of services provided within the framework based on its ORM The convenience of;
# Theoretically, it can be switched off ORM Module, but this is equivalent to demolishing and redecorating the renovated house. It is better to 1 At the beginning, the hair embryo room was completely renovated.
#3.Django Its selling point is ultra-high development efficiency and its performance expansion is limited; Adopt Django The project, when the traffic reaches 1 After the scale is fixed, it needs to be reconstructed to meet the performance requirements.
#4.Django It is suitable for small and medium-sized websites, or as a tool for large websites to quickly realize the prototype of products.
#5.Django The design philosophy of template is to completely separate code and style; Django The possibility of coding and processing data in templates is fundamentally eliminated.
2. Comparison of Django, Flask and Tornado
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
3. What are wsgi, uwsgi, uWSGI?
#WSGI:
# web Server gateway interface , Yes 1 Set of agreements. Used to receive the user request, encapsulate the request for the first time, and then hand the request to the web Framework
# Realization wsgi Modules of the protocol:
# 1.wsgiref, Is essentially writing 1 A socket Server for receiving user requests (django)
# 2.werkzeug, Is essentially writing 1 A socket Server for receiving user requests (flask)
#uwsgi:
# And WSGI1 Sample is 1 A communication protocol, which is uWSGI Exclusive protocol of server , Used to define the type of information to be transmitted
#uWSGI:
# Yes 1 A web Server , Realized WSGI Agreement ,uWSGI Agreement ,http Agreement ,
4. What is the lifecycle of an django request?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
5. What are FBV and CBV?
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
6. How do I add a decorator to my CBV program?
# Introduce method_decorator Module
#1. Adding a decorator directly to the class
#@method_decorator(test,name='dispatch')
#class Loginview(View):
# pass
#2. Add a decorator directly in front of the processed function
#@method_decorator(test)
# def post(self,request,*args,**kwargs):pass
7. Brief introduction of MVC and MTV
#MVC Software system is divided into 3 Basic parts: model (Model) , view (View) And controller (Controller)
#Model Responsible for mapping business objects to databases (ORM)
#View : Responsible for interaction with users
#Control Accept the user's input, call the model and view to complete the user's request
#Django Framed MTV The design pattern draws on the MVC The idea of framework ,3 The sections are: Model , Template And View
#Model( Model ) Objects responsible for business objects and databases (ORM)
#Template( Template ) Responsible for presenting the page to the user
#View( View ) Is responsible for the business logic and calls the Model And Template
# In addition ,Django And 1 A urls Dispenser ,
# It will 1 All URL Page requests for distribution to different view Deal with ,view And then call the corresponding Model And Template
8. The role of name in django routing system?
# Used to reverse resolve routes , Equivalent to giving url Take an alias, as long as the name remains unchanged , Even if the corresponding url Change
# This article can also be found by this name url
9. List the built-in components of django?
#1.Admin That's right model Add, delete, modify and query the provided components for the corresponding data table in
#2.model Component: Responsible for operating the database
#3.form Components: 1. Generate HTML Code 2. Data validity check 3 Verification information is returned and displayed
#4.ModelForm Component is used for database operations , It can also be used for authentication of user requests
10. What are the functions and application scenarios of Django and MIDDLEWARES middleware?
# Middleware is between request And response Between processing 1 Channel processing process , Used to change globally Django The input and output of the.
# Simply put, middleware helps us do it before and after the execution of the view function 1 Some extra operations
# For example:
#1.Django The project is enabled by default csrf Protection , Pass on each request CSRF Middleware checks whether there is a correct #token Value
#2. When the user sends a request on the page, through the user-defined authentication middleware, judge whether the user has logged in or not, and log in without logging in.
#3. When a user requests to come over, whether the user is in the white list or in the black list is judged
11. List five methods of django middleware?
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
0
12. When was the request object of django created?
#class WSGIHandler(base.BaseHandler):
# request = self.request_class(environ)
# Request to walk to WSGIHandler Class, execute the __cell__ Method, setting the environ Packaged into request
13. How is Django redirection implemented? What status code is used?
#1. Use HttpResponseRedirect
#from django.http import HttpResponseRedirect
#2. Use redirect And reverse
# Status code: 301 And 302
#301 And 302 The difference:
# Same point: Both mean redirection, and the browser will automatically jump to the status code returned by the server 1 A new one URL Address
# Differences:
#301 A more common scenario is to use domain name jump. For example, we visit http://www.baidu.com Will jump to https://www.baidu.com
# Represents an old address A Has been permanently removed
#302 Used to make temporary jumps, such as unlogged users visiting the user center and redirecting to the login page. Represents an old address A The resource of is still there (still accessible), and this redirection is only temporarily from the old address A Jump to address B
14. xxss Attack
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
3
15. Implementation mechanism of csrf in django
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
4
16. When sending post requests using ajax based on django, which method can be used to carry csrf token?
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
5
17. Django itself provides runserver, why can't it be deployed? (Difference between runserver and uWSGI)
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
6
18. Differences between cookie and session:
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
7
19. Enumerate all the methods in django orm (all the methods of the QuerySet object)
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
8
20. What is the difference between only and defer?
#1.Django Take a big and comprehensive direction , High development efficiency. Its MTV Framework , Bring your own ORM,admin Background management , Bring your own sqlite Database and server for development test
# It improves the super high development efficiency for developers
#2.Flask Is a lightweight framework , Freedom , Flexible , Strong scalability , Core is based on Werkzeug WSGI Tools and jinja2 Template engine
#3.Tornado Going in the direction of less and more precision , Superior performance. It is best known for its asynchronous non-blocking design
#Tornado Two core modules of:
# 1.iostraem For non-blocking socket Simple encapsulation
# 2.ioloop : Right I/O Multiplexed encapsulation, which implements the 1 Singleton
9
21. What is the difference between select_related and prefetch_related?
# When there are foreign keys, it can reduce the number of database requests , Improve performance
#select_related Through multiple tables join Association query ,1 Obtain all data in a secondary manner , Execute only 1 Times SQL Query
#prefetch_related Query each table separately , Then deal with it according to the relationship between them , Execute the query twice
22. What is the difference between filter and exclude?
# The values obtained are all QuerySet Object ,filter Select the that meets the conditions ,exclude: Exclude those that meet the conditions .
23. What are the roles of F and Q?
#F: Operating on different fields of the data itself Such as : Compare and update
#Q Used to construct complex query conditions Such as: & | Operation
24. What is the difference between values and values_list?
#values : Dictionary's queryset
#values_list : Tuple-taking queryset
25. How do I bulk create data using django orm?
#bulk_create()
#objs=[models.Book(title=" Books {}".format(i+15)) for i in range(100)]
#models.Book.objects.bulk_create(objs)
26. The role of Form and ModeForm of django?
#Form Function:
# 1. Generate at the front end HTML Code
# 2. Check the validity of the data
# 3. Returns verification information and displays
#ModeForm Generate from model classes From Component , And can operate the database
27. In the Form component of django, if the field contains choices parameters, there are two ways to update the data source in real time.
#WSGI:
# web Server gateway interface , Yes 1 Set of agreements. Used to receive the user request, encapsulate the request for the first time, and then hand the request to the web Framework
# Realization wsgi Modules of the protocol:
# 1.wsgiref, Is essentially writing 1 A socket Server for receiving user requests (django)
# 2.werkzeug, Is essentially writing 1 A socket Server for receiving user requests (flask)
#uwsgi:
# And WSGI1 Sample is 1 A communication protocol, which is uWSGI Exclusive protocol of server , Used to define the type of information to be transmitted
#uWSGI:
# Yes 1 A web Server , Realized WSGI Agreement ,uWSGI Agreement ,http Agreement ,
6
28. What is the effect of the on_delete parameter in the ForeignKey field in Model of django?
#WSGI:
# web Server gateway interface , Yes 1 Set of agreements. Used to receive the user request, encapsulate the request for the first time, and then hand the request to the web Framework
# Realization wsgi Modules of the protocol:
# 1.wsgiref, Is essentially writing 1 A socket Server for receiving user requests (django)
# 2.werkzeug, Is essentially writing 1 A socket Server for receiving user requests (flask)
#uwsgi:
# And WSGI1 Sample is 1 A communication protocol, which is uWSGI Exclusive protocol of server , Used to define the type of information to be transmitted
#uWSGI:
# Yes 1 A web Server , Realized WSGI Agreement ,uWSGI Agreement ,http Agreement ,
7
29. How does django implement websocket?
#WSGI:
# web Server gateway interface , Yes 1 Set of agreements. Used to receive the user request, encapsulate the request for the first time, and then hand the request to the web Framework
# Realization wsgi Modules of the protocol:
# 1.wsgiref, Is essentially writing 1 A socket Server for receiving user requests (django)
# 2.werkzeug, Is essentially writing 1 A socket Server for receiving user requests (flask)
#uwsgi:
# And WSGI1 Sample is 1 A communication protocol, which is uWSGI Exclusive protocol of server , Used to define the type of information to be transmitted
#uWSGI:
# Yes 1 A web Server , Realized WSGI Agreement ,uWSGI Agreement ,http Agreement ,
8
30. How do I set up read-write separation in django orm?
#WSGI:
# web Server gateway interface , Yes 1 Set of agreements. Used to receive the user request, encapsulate the request for the first time, and then hand the request to the web Framework
# Realization wsgi Modules of the protocol:
# 1.wsgiref, Is essentially writing 1 A socket Server for receiving user requests (django)
# 2.werkzeug, Is essentially writing 1 A socket Server for receiving user requests (flask)
#uwsgi:
# And WSGI1 Sample is 1 A communication protocol, which is uWSGI Exclusive protocol of server , Used to define the type of information to be transmitted
#uWSGI:
# Yes 1 A web Server , Realized WSGI Agreement ,uWSGI Agreement ,http Agreement ,
9
31. How to create 1 log record when data is added to an orm table in django.
32. What is the built-in caching mechanism for django?
# Whole station cache
MIDDLEWARE_CLASSES = (
' django.middleware.cache.UpdateCacheMiddleware', # No. 1 1
'django.middleware.common.CommonMiddleware',
' django.middleware.cache.FetchFromCacheMiddleware', # Finally
)
# View cache
from django.views.decorators.cache import cache_page
import time
@cache_page(15) # The timeout time is 15 Seconds
def index(request):
t=time.time() # Get the current time
return render(request,"index.html",locals())
# Template cache
{% load cache %}
<h3 style="color: green"> Not caching :-----{{ t }}</h3>
{% cache 2 'name' %} # Saved key
<h3> Cache :-----:{{ t }}</h3>
{% endcache %}
33. Can the cache of django use redis? If possible, how to configure it?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
1
34. What is the difference between filter and simple_tag in the template of django?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
2
35. The role of django-debug-toolbar?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
3
36. How do you implement unit testing in django?
37. Explain the meaning of db first and code first in orm?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
4
38. How do you generate classes in model from database tables in django?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
5
39. What are the advantages and disadvantages of using orm and native sql?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
6
40. What does the contenttype component of django do?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
7
41. Talk about your understanding of restful specification?
#1.wsgi, The request is encapsulated and handed to web Framework ( Flask , Django )
#2. Middleware, which validates the request or adds other relevant data to the request object, such as: csrf , request.session -
#3. Route matching Depending on what the browser sends url To match different view functions
#4. View function, in which business logic is processed, may involve: orm , templates => Render -
#5. Middleware, which processes the response data.
#6.wsgi, Sends the content of the response to the browser.
8
42. What does the idempotence of an interface mean?
#1. Is the interface of the system 1 A kind of commitment ( Instead of realizing )
#2. Promise that as long as the interface is called successfully, , The impact of multiple external calls on the system is 1 To , Do not repeat operations on resources
43. What is RPC?
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
0
44. Why use API
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
1
45. Why use the django rest framework framework?
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
2
46. What are the components in the django rest framework framework?
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
3
47. What classes can views in the django rest framework framework inherit?
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
4
48. Briefly describe the authentication process of django rest framework framework
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
5
49. How does django rest framework realize user access frequency control
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
6
50. The role of the rest_framework serialization component, and some hook methods for foreign key relationships
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
7
51. What do you need to do in advance before providing users with an interface
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
8
52. PV and UV
#FBV And CBV The essence is 1 Like
# Function-based views are called FBV The class-based view is called CBV
# In python Use in CBV Advantages of:
#1. Improve the reusability of code and use object-oriented technologies, such as Mixin (Multiple inheritance)
#2. You can use different functions for different HTTP Method, not through many if Judge and improve code readability
9
53. What is cross-domain and the solution:
# Introduce method_decorator Module
#1. Adding a decorator directly to the class
#@method_decorator(test,name='dispatch')
#class Loginview(View):
# pass
#2. Add a decorator directly in front of the processed function
#@method_decorator(test)
# def post(self,request,*args,**kwargs):pass
0
54. How to achieve user login authentication
# Introduce method_decorator Module
#1. Adding a decorator directly to the class
#@method_decorator(test,name='dispatch')
#class Loginview(View):
# pass
#2. Add a decorator directly in front of the processed function
#@method_decorator(test)
# def post(self,request,*args,**kwargs):pass
1
55. How to convert dict to the format of url:
# Introduce method_decorator Module
#1. Adding a decorator directly to the class
#@method_decorator(test,name='dispatch')
#class Loginview(View):
# pass
#2. Add a decorator directly in front of the processed function
#@method_decorator(test)
# def post(self,request,*args,**kwargs):pass
2