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())

 

posted on 2018-07-20 11:00  python我的最爱  阅读(449)  评论(0编辑  收藏  举报