【问题标题】:how do i return in my class based view after updating data更新数据后如何在基于类的视图中返回
【发布时间】:2019-11-25 06:10:02
【问题描述】:

这是我的views.py函数:

class ProfileUpdateView(UpdateView):
    model = UserProfile
    fields = ['first_name','last_name','username','gender','datetimepicker','p_photo','h_photo','subtitles','political_incline',
            'about_me','birthplace','lives_in','country','province','city','occupation',
            'relationship_status','website','phone_number','religious_belifs','political_incline',
            'facebook','twitter','RSS','dibble','spotify']

urls.py

url(r'^updateprofile/(?P<pk>\d+)/$',views.ProfileUpdateView.as_view(success_url='/postlist/')),

【问题讨论】:

  • 你想达到什么目的?

标签: python django python-3.x web django-models


【解决方案1】:

在您的视图中添加如下所示的成功网址

success_url = reverse_lazy('the_page_required')

如果您想进入详细视图,您也可以这样定义。

def get_success_url(self):
         return reverse('detail_view_url', kwargs={'pk': self.pk})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多