Django не выводит переменную массива в шаблоне
В моей функции контроллера django я получаю из базы данных "аннотации" конкретного веб-сервера.
Для всех аннотаций я строю массив annotationsId, annotationsCode, annotationsName. Это
annotationsId = [1, 2, 3, 4, 5]
annotationsCode = ['codicefiscale', 'partitaiva', 'telefono', 'data', 'targa']
annotationsName = ['codice fiscale', 'partita iva', 'telefono', 'data', 'targa']
Я передаю эти массивы в view_process_show_saveandanalize.html через tmplAnnVar.
Мой вывод таков
<li><a class="dropdown-item active" href="#" data-active="1" data-annotation-web-server-id data-annotation-code data-func></a> </li>
Как вы видите, микроданные (пример data-annotation-web-server-id) не имеют значения
def show_results(request):
#verifico che L'utente abbia scelto un server di annotazioni
isChooseWebServer = False
userId = int(request.session['id'])
userWebServerDao = UserWebServerDAO()
userWebServerRec = userWebServerDao.getUserWebServer(userId)
userWebServerRec = userWebServerRec[0]
idWebServer = userWebServerRec["web_server_id"]
if idWebServer > 0:
isChooseWebServer = True
isThereAnnotation = False
#ottengo la lista delle annotazioni del server scelto dall'utente
annotationWebServerDao = AnnotationWebServerDAO()
annotations = annotationWebServerDao.getAnnotationsWebServer(idWebServer)
if len(annotations) > 0:
isThereAnnotation = True
annotationsName = []
annotationsCode = []
annotationsId = []
i = 0
for annot in annotations:
print(annot)
annotationsId.append(annot["annotation_web_server_id"])
annotationsCode.append(annot["annotation_code"])
annotationsName.append(annot["annotation_name"])
i = i + 1
print(annotationsCode)
print(annotationsName)
print(annotationsId)
messageSaveAndAnalize = ""
if isChooseWebServer is False:
messageSaveAndAnalize = "imposta server annotazioni"
elif isThereAnnotation is False:
messageSaveAndAnalize = "Non ci sono annotazioni per il server scelto."
tmplAnnVar = {}
tmplAnnVar["messageSaveAndAnalize"] = messageSaveAndAnalize
tmplAnnVar["annotationsId"] = annotationsId
tmplAnnVar["annotationsCode"] = annotationsCode
tmplAnnVar["annotationsName"] = annotationsName
dataAnnotationsRes = ""
dataAnnotationsRes = render_to_string('pygiustizia/home/view_process_show_saveandanalize.html',{ "tmplAnnVar": tmplAnnVar})
res = {}
res["status"] = "ok"
res["data"] = {}
res["data"]["view_saveandanalize"] = dataAnnotationsRes
res["redirect"] = ""
return JsonResponse(res)
pygiustizia/home/view_process_show_saveandanalize.html
<button type="button" class="btn btn-primary btnSaveSearch">Salva e analizza</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split"
data-bs-display="static" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start">
{% for annotId in tmplAnnVar.annotationsId %}
{% with c=forloop.counter0 %}
<li><a class="dropdown-item active"
href="#"
data-active="1"
data-annotation-web-server-id = "{{tmplAnnVar.annotationsId.c}}"
data-annotation-code = "{{tmplAnnVar.annotationsCode.c}}"
data-func="{{tmplAnnVar.annotationsCode.c}}">{{tmplAnnVar.annotationsName.c}}</a>
</li>
{% endwith %}
{% endfor %}
</ul>
Я тестирую data-annotation-web-server-id = "{{c}}"
и он печатает 0,1,2,3,4
Я тестирую data-annotation-web-server-id = "{{tmplAnnVar.annotationsId.0}}"
и он печатает 1
Я тестирую data-annotation-web-server-id = "{{tmplAnnVar.annotationsId.c}}"
и он выводит data-annotation-web-server-id а именно НИЧЕГО