好吧,你会是这样的:
class MyTemplateView(TemplateView):
def get(self, request, *args, **kwargs):
return HttpResponseRedirect('/<your path here>/')
您可以在此处了解更多信息,并在此处更详细地了解它。
如果您想传递帖子数据,那么您所要做的就是:
class MyTemplateView(TemplateView):
def get_context_data(self, **kwargs):
return HttpResponseRedirect(reverse('/<your url here>/', [params]))
您也可以使用该post
功能执行此操作。
class MyTemplateView(TemplateView):
def post(self, request, *args, **kwargs):
# do what you want with post data
# you can get access via request.POST.get()
return HttpResponseRedirect('/<your url>/')
# Or use the above example's return statement, if you want to pass along parameters