Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

944
Views
Django, view get list of dictionaries from request

I have an AJAX request call (with JQuery) to my django view. It sends to view this kind of data:

{"cityId": 1, "products_with_priority": [{"id": 1, "priority": 1}, {"id": 2, "priority": 2}, {"id": 3, "priority": 3}, {"id": 4, "priority": 4}, {"id": 5, "priority": 5}]}

In my django view, I'm trying to get this list like this:

def my_view(request):
    city_id = request.POST.get('city_id')
    products_priorities = request.POST.getlist("products_with_priority")

Where city_id returns 1 and products_with_priority returns empty array.

How it is possible to receive array of dictionaries from request?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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'))
over 4 years ago · Santiago Trujillo Report

0

Convert the data to json string.

And receive it like

data = json.loads(request.POST)
over 4 years ago · Santiago Trujillo Report

0

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']
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!