from django.views import View class Home(View): def dispatch(self, request, *args, **kwargs): print('before') result = super(Home,self).dispatch(request, *args, **kwargs) print('after') return result def get(self, request): print(request.method) return render(request, 'home.html') def post(self, request): print(request.method, 'POST') return render(request, 'home.html')
这是views文件中定义home函数
在urls文件中
添加
url(r'^home/', views.Home.as_view())