I just posted this question jQuery - passing arrays in post request, where I don't to send arrays in post request, but there is no problem in jQuery code.
The problem is with receiving the POST request in django. I did like this.
def portfolio_add(request): ukeys = request.POST.getlist('ukeys') ........etc.......
But I'm getting ukeys values as u'[]'
. When I checked with just request.POST
I got the values as u"<QueryDict: {u'ukeys[]': [u'68c04', u'16149']}>"
So, How to get those values as a list in Django?
Thanks!
Django pass POST data to view The input fields defined inside the form pass the data to the redirected URL. You can define this URL in the urls.py file. In this URLs file, you can define the function created inside the view and access the POST data as explained in the above method. You just have to use the HTTPRequest.
request. POST is an attribute of this request object, it's a QueryDict (much similar to a normal Python dict). It contains the HTTP POST parameters that are sent to your view.
Using Form in a View In Django, the request object passed as parameter to your view has an attribute called "method" where the type of the request is set, and all data passed via POST can be accessed via the request. POST dictionary. The view will display the result of the login form posted through the loggedin.
META contains all the metadata of the HTTP request that is coming to your Django server, it can contain the user agent, ip address, content type, and so on.
jQuery POST's arrays with the []
suffix because PHP and some web frameworks understand that convention, and re-build the array on the server-side for you automatically. Django doesn't work that way, but you should be able to access the data via:
ukeys = request.POST.getlist('ukeys[]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With