我想使success_url
像是动态的,而不是给路径success_url =/company/
我要给路径名。这样的示例success_url =superadmin_company_update
path('update/<int:pk>/', views.CompanyUpdateView.as_view(), name='superadmin_company_update'),
class CompanyUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Company
success_url = '/company/'
template_name = 'company/company_form.html'
fields = ['company_name', 'company_description', 'company_email',
'company_website', 'company_address', 'company_phone', 'company_status',
'company_monthly_payment', 'company_logo']
答案 0 :(得分:0)
找到了get_sucess_url
东西,只需要删除success_url = '/company/'
from django.urls.base import reverse
...
class CompanyUpdateView(LoginRequiredMixin, generic.UpdateView):
model = Company
template_name = 'company/company_form.html'
fields = ['company_name', 'company_description', 'company_email',
'company_website', 'company_address', 'company_phone', 'company_status',
'company_monthly_payment', 'company_logo']
def get_success_url(self):
return reverse('superadmin_company')