Exemple #1
0
 def post(self, request):
     form = PublishForm(request.POST)
     if form.is_valid():
         form.save()
         res = {'code': 0, 'result': '添加出版商成功'}
     else:
         # form.errors会把验证不通过的信息以对象的形式传到前端,前端直接渲染即可
         res = {'code': 1, 'errmsg': form.errors}
     return JsonResponse(res, safe=True)
Exemple #2
0
 def post(self, request, *args, **kwargs):
     pk = kwargs.get('pk')
     p = self.model.objects.get(pk=pk)
     form = PublishForm(request.POST, instance=p)
     if form.is_valid():
         form.save()
         res = {"code":0,"result":"更新出版商成功", 'next_url':self.next_url}
     else:    
         res = {"code":1,"errmsg":form.errors,'next_url':self.next_url}
     return render(request,settings.JUMP_PAGE,res)