django dispatch
Posted Howhy Blogs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django dispatch相关的知识,希望对你有一定的参考价值。
from django.views import View # 这里Home需要继承View class Home(View): # 这样这里就相当于一个装饰器的功能,可以自己定制化内容 def dispatch(self, request, *args, **kwargs): # 调用父类中dispatch方法 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) return render(request, "home.html")
这样从效果就可以看出当再次访问home页面的时候,每次都需要打印before以及after
以上是关于django dispatch的主要内容,如果未能解决你的问题,请参考以下文章