我有一个基于类的视图:
class UpdateProfileView(UpdateView):
model = models.Profile
form_class = forms.ProfileForm
template_name = 'userprofile/add_user_profile.html'
success_url = '/'
我想添加一种方法,在将数据更新到数据库之前,它还会将数据更新为自定义API,但我对django基于类的视图了解不多。
如何在将数据发送到数据库之前将其连接起来我获取表单数据并将其发布到我拥有的API中?
答案 0 :(得分:1)
听起来像覆盖form_valid()
将是一个很好的方式。
def form_valid(self, form):
post_to_api(form.cleaned_data)
# now call superclass to save the form
return super(UpdateProfileView, self).form_valid(form)