我有一个严重的问题,我需要使用cleaned_data方法和getlist方法来获取表单的值,因为我有通过ajax发送的数据。

但这不起作用,并且我的终端中出现此错误:

Exception happened during processing of request from ('127.0.0.1', 56694)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 129, in __init__
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 710, in finish
    self.wfile.close()
  File "/usr/lib/python2.7/socket.py", line 279, in close
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
[17/May/2015 12:08:57] "POST /mafiche HTTP/1.1" 200 20921
error: [Errno 32] Broken pipe

我的form.html:

<form method="POST" id="formMod" action="{% url 'myfic' %}" >
    {% csrf_token %}
    {{ form.name|bootstrap }}
    {{ form.surname|bootstrap }}
    <div class="row">
            <div class="col-md-6">
                {{ form.comp_form|bootstrap }}
            </div>

            <div id="comp_details" class="col-md-6">
            </div>
    </div>
    ...
    <input type="submit" id="the_button" class="btn btn-success" value="Validate">

提交表单后,它将调用此函数js:

function send_numbers(){
   $.post("http://localhost:8000/myfic",{"theNumbers[]": [1,2,3],});
}

$(document).ready(function() {
    $("#formMod").submit(function() {
        send_numbers();
    });
});

我的观点 :

def myfic(request):
    if request.method == "POST" :
        form = AuthenticateForm(request.POST, request.FILES) #It's the form in the html
        numbers = request.POST.getlist("theNumbers[]")      

        if form.is_valid() :
            # Update
            print("OKKKKK")
        ...

如何获取我的表单和函数ajax的值? 因为我摔倒了要么是另一个...

===============>>#1 票数:0

您需要return false; submit()函数中阻止默认的浏览器提交。

  ask by YassVegas translate from so

未解决问题?本站智能推荐: