使用UpdateView的success_url返回到PagedFilteredTableView [英] Using UpdateView's success_url to return to PagedFilteredTableView

查看:139
本文介绍了使用UpdateView的success_url返回到PagedFilteredTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循此讨论来实施表格已过滤内容。在显示的表中,我在每行中有一个单元格,允许用户单击链接并编辑该行的数据。在此过程中,使用UpdateView。



在UpdateView表单提交时,我想返回用于启动连接的过滤内容/表编辑行的数据。



在下面的代码中,'next是{}'打印所需的URL,但框架返回错误:
视图...没有返回HttpResponse对象。它返回了无。



我应该使用哪个功能让UpdateView返回到所需的URL?

  class UpdateMyModelView(UpdateView):
model = MyModel
template_name ='data_form.html'
fields = ['A' ,'B','C']

def form_valid(self,form):
instance = form.save(commit = False)
r = self.request
p = r.POST
print('request is:{}'。format(r))
print('p is {}'format(p))
print POST.next是:{}'。format(p ['next']))
self.success_url = p ['next']
print('next is {}'format(self。 success_url))
super(UpdateMyModelView,self).form_valid(form)


解决方案

您的视图没有返回语句,因此它返回。如果您调用 super(),那么您应该返回结果。

  return super(UpdateMyModelView,self).form_valid(form)

在这种情况下,它看起来像更好地覆盖 get_success_url 而不是 form_valid

  def get_success_url(self):
return self.request.POST.get('next','/ default-url /')


I followed this discussion to implement a table with filtered content. In the displayed table, I have a cell in each row that allows a user to click on a link and edit that row's data. In the process, UpdateView is used.

On a submit from UpdateView's form, I'd like to return to the filtered content/table that was used to initiate the connection for editing the row's data.

In my code below, the 'next is {}' prints the desired URL but the framework returns an error: The view ...didn't return an HttpResponse object. It returned None instead.

Which function should I use to have the UpdateView return to the desired URL?

class UpdateMyModelView(UpdateView):
    model = MyModel
    template_name='data_form.html'
    fields = ['A', 'B', 'C']

    def form_valid(self, form):
        instance = form.save(commit=False)
        r = self.request
        p = r.POST
        print ('request is: {}'.format(r))
        print ('p is {}'.format(p))
        print ('request POST.next is: {}'.format(p['next']))
        self.success_url = p['next']
        print ('next is {}'.format(self.success_url))
        super(UpdateMyModelView, self).form_valid(form)

解决方案

Your view does not have a return statement, so it is returning None. If you call super(), then you should return the result.

return super(UpdateMyModelView, self).form_valid(form)

In this case, it looks like it would be better to override get_success_url instead of form_valid:

def get_success_url(self):
    return self.request.POST.get('next', '/default-url/')

这篇关于使用UpdateView的success_url返回到PagedFilteredTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆