I'm trying to cycle an array that comes from a node in mongoDB, this is Mongo's object:
{
"nombre": "Sebastián Yatra",
"paises":["México","Argentina","Perú"]
}
The view controller is this
from django.shortcuts import render
from pymongo import MongoClient
def paises( req ):
client = MongoClient()
obj = { 'obj': client['mydb']['paises'].find() }
return render( req, 'index.html', obj )
This is how I'm cycling in the view with Django
<h5>{{ obj.nombre }}</h5> #aquí si imprime Sebastián Yatra
<ul>
{% for pais in obj.paises %}
<li>{{ pais[0] }}</li>
{% endfor %}
</ul>
<p>{{ len(obj.paises) }} encontados</p>
First he tells me
Could not parse this remainder: 'obj.paises' from 'len (obj.paises)'
And if I remove the line it says
Could not parse this remainder '[0]' from 'country [0]'
I'm still a novice with Python, my experience tells me that first I must declare a variable that increases type pais[i]
but I do not know where to declare i = 0, and then where to increase it.
What can I do with these 2 erors?