1
def post(self, request, *args, **kwargs):
    self.company.name = request.POST['company_name']
    self.company.certification = request.POST['company_pic_url']
    self.company.save()
    return http.HttpResponseRedirect('/company')

这里,company 是一个模型实例,名称和证书在 save() 之后不会改变

然而

def post(self, request, *args, **kwargs):
    company = self.company
    company.name = request.POST['company_name']
    company.certification = request.POST['company_pic_url']
    company.save()
    return http.HttpResponseRedirect('/company')

效果很好有人可以解释一下吗?谢谢

4

0 回答 0