sql >> Base de Datos >  >> NoSQL >> MongoDB

Template Render no está pasando la variable agregada de pymongo a la plantilla

Recortando esto a lo que está buscando en este punto (y corrigiendo algo de sintaxis en su plantilla), intente una lista de comprensión:

from django.shortcuts import render

def gettheAudit(request):
    theURLs = [x for x in mycol.aggregate([{"$unwind":"$tags"},{'$match': {'tags.tag.name':'A A',}},{'$project': {'url': 1, 'AR': 1, 'tags.tag.name': 1, 'tags.variables': 1, '_id': 0}},])]
    return render(request, 'templates/a.html', {'theURLs': theURLs})

plantillas/a.html:

   <ul>
      <li><h1>URLSSSS</h1></li>
      {% for theURL in theURLs %}
         <li>{{ theURL }}</li>
      {% endfor %}
   </ul>