直接使用就可以撒,你的类至少继承了django.views.generic.view,最基本的一个类,这个类里有dispatch函数负责方法分发:
def dispatch(self, request, *args, **kwargs):
# Try to dispatch to the right method; if a method doesn't exist,
# defer to the error handler. Also defer to the error handler if the
# request method isn't on the approved list.
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
else:
handler = self.http_method_not_allowed
return handler(request, *args, **kwargs)
里面return的request直接拿来用就行:
def get(self, request, *args, **kwargs):
pass
session直接request.session,和fbv使用方法一样。