就是在視圖裏使用類處理請求函數
優勢post
代碼邏輯url
urlspa
from django.conf.urls import url from myapp.views import MyView urlpatterns = [ url(r'^index/$', MyView.as_view()), ]
view.pycode
from django.http import HttpResponse from django.views import View class GreetingView(View): name = "lin" def get(self, request): return HttpResponse(self.name)
實現本質: 基於反射實現的csrf
流程:由路由---->as_view()方法--->view中的dispatch方法(反射實現的)中間件
首先執行url中的as_view()方法
執行view方法