我有一个templateview,代码在这里是怎么做的
class MyTemplateView(TemplateView):
def get_context_data(self, **kwargs):
context = super(UBaseTemplateView, self).get_context_data(**kwargs)
# i want to redirect another url in here
# how to do it
return context
Run Code Online (Sandbox Code Playgroud)
好吧,你会这样的:
class MyTemplateView(TemplateView):
def get(self, request, *args, **kwargs):
return HttpResponseRedirect('/<your path here>/')
Run Code Online (Sandbox Code Playgroud)
如果你想传递帖子数据,那么你所要做的就是:
class MyTemplateView(TemplateView):
def get_context_data(self, **kwargs):
return HttpResponseRedirect(reverse('/<your url here>/', [params]))
Run Code Online (Sandbox Code Playgroud)
您也可以使用该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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3813 次 |
| 最近记录: |