Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

942
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Convert the data to json string.

And receive it like

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda