DjangoCBV source code analysis

FBV

Function is based on a view FBV

CBV

CBV is a view of class-based

CBV basic wording

North Korea login to submit requests get executed automatically MyLogin inside the get method
post request will automatically perform MyLogin inside the post method to submit
a method to automate Why MyLogin correspond to different request method? ? ? ?

Also written in the views.py

from django.views import View
class MyLogin(View):
    def get(self,request):
        return render(request,'login.html')   //写功能
    def post(self,request):
        return HttpResponse('我是类里面的post方法')     /写功能

urls.py in:

# CBV路由配置
    url(r'^login/',views.MyLogin.as_view()),

CBV source code analysis

1. study the source code of a breakthrough

url(r'^login/',views.MyLogin.as_view())

guess:

as_view要么是类里面定义的普通函数 @staticmethod
要么是类里面定义的绑定给类的方法  @classmethod

2. Enter the source is found equivalence class @classmethod binding method, and the function returns the name of the view

3. equivalence

4.view function returns self.dispatch (request, * args, ** kwargs), go Chou Chou

The acquisition request mode, and to lower case. Into self.http_method_names Chou Chou. Determine whether the current request mode the default mode 8 request

6.http_method_names there is a list of a bunch of ways request. 8

7. retreated to Step 5, if the judgment is positive through and continue to go down

8. get, post automatically execute a corresponding function based on the return value

source code analysis settings

1. Problem thrown.

django settings源码
    django暴露给用户一个可以自定义的配置
    但是内部也有默认的配置
    
    用户配置了就用用户的 用户没有配就用默认的

Django exposes a user to settings.py file. Inside the user to configure the user to use, if not configured to use Django's own. The principle is how to achieve? ? ? ?

Guess you like

Origin www.cnblogs.com/guyouyin123/p/12163718.html