4π
β
Ensure your dataType is json
, and stringify your array:
dataType: 'json',
data: {'cityId': 1, 'products_with_priority': JSON.stringify([{"id": 1, "priority": 1}, {"id": 2, "priority": 2}, {"id": 3, "priority": 3}, {"id": 4, "priority": 4}, {"id": 5, "priority": 5}])}
Then use the (standard Python library) json
βs loads()
method in your Django view:
products_priorities = json.loads(request.POST.get('products_with_priority'))
π€nb1987
1π
Convert the data to json string.
And receive it like
data = json.loads(request.POST)
π€Sumeet P
- [Django]-Django stops serving static files when DEBUG is False
- [Django]-How to add html classes to a Django template 'for-loop' dynamically?
- [Django]-How import and use csrf token in django 1.11?
- [Django]-Celery raise error while passing my queryset obj as parameter
1π
send your data in a json string to django view and then
Try
def my_view(request):
data = OrderedDict()
data = json.loads(request.POST)
city_id = data['city_id']
π€TuXin Zhang
- [Django]-What is different between "DRF Throttling" and "Django Axes"
- [Django]-Django adding a feedback form on every page
- [Django]-Django run manage.py generates OS error in OS X Yosemite
0π
In AJAX request, make sure you include the header:
content-type: application/json
Then if you are using Python 3 as I do, in Django View:
def my_view(request):
received_json = json.loads(request.read().decode('utf-8'))
products_priority = received_json['products_with_priority']
π€Vamei
0π
If your are sending POST
data as jQuery (raw) data
, then you can access it via body
as a string
. From which you can load it as JSON
. Hope the below example helps you.
def my_view(request):
data = json.loads(request.body)
city_id = data.get('cityId')
products_priorities = data.get("products_with_priority")
π€Sathish Kumar VG
- [Django]-Django Paginate by Year
- [Django]-Can I have 2 Django sites using 2 different version of Python on 1 domain?
Source:stackexchange.com