'str'对象没有属性'get'?

时间:2020-08-02 18:33:28

标签: jquery django

我尝试使用Django表单和ajax更新一些数据,问题是该表单不接受'POST ['dat'],而且我不知道为什么?任何解决方案

jquery:

ProjStr = """[Project].[PROJECT_NUMBER].&[200283.0.001.01.000]""" & ", " & """[Project].[PROJECT_NUMBER].&[200283.0.001.02.000]"""

views.py:

 $.ajax({ 
            headers: {
               
                "X-CSRFToken": csrftoken
            },
              data: {'dat' : $('#form-one').serialize(),'id':id}, 
              type: 'POST', 
              url: '/commande/update2post/', 
              success: function(response) { 
                $.ajax({ 
            headers: {
               
                "X-CSRFToken": csrftoken
            },
  });

forms.py


def update2post(request):
    

    if request.method == 'POST' and request.is_ajax:
        print(request.POST['id'])
        print(request.POST.get('id'))
        commande = get_object_or_404(Commande, id=request.POST['id'])
        das = request.POST['dat']
       
        form = Commande_Form2(data=request.POST['dat'],instance=commande)// the issue ...
        if form.is_valid():
         form.save()

0 个答案:

没有答案