Синтаксис "cellule.utilisateurs.all" работает с шаблоном HTML Django, но не работает с шаблоном TeX Django.
С шаблонами HTML Django он отображается в результирующем HTML-файле, отображаемомв веб-браузере список пользователей («utilisateurs» на французском языке) каждой ячейки («cellule» на французском языке).
С помощью шаблона TeX Django в веб-браузере появляется следующее сообщение об ошибке:
объект 'method' не повторяется
Вот различные фрагменты кода:
HTML-шаблон :
<html charset="UTF-8">
<body>
<p style="font-size:40px;color:blue">INFOREFLEX_GENER_HTML_CELLULES, version 1.0 (23/07/2019)</p>
<p style="font-size:30px;color:red">(Date de l'import des données en base : {{ dateDernierExport }})</p>
{% for cellule in listeCellules %}
<a id="{{ cellule.dpt_im }}"></a>
<h1 style="font-size:60px;color:blue">{{ cellule.dpt_im }}</h1>
<table border="1">
{% for utilisateur in cellule.utilisateurs.all %}
<tr>
<td style="background-color:moccasin;font-weight: bold"><a href="http://annuaire-entreprise.inetpsa.com/?action=exec_recherche_personne&identifiant={{ utilisateur.cod_user }}" target="_blank">{{ utilisateur.cod_user }}</a>-{{ utilisateur.lib_prenom }} {{ utilisateur.lib_nom_usuel }}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
</body>
</html>
Шаблон TeX :
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{color, colortbl}
\usepackage{hyperref}
\usepackage[margin=0.25in]{geometry}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
\title{INFOREFLEX_GENER_HTML_CELLULES, version 1.0 (23/07/2019)}
\author{OPEN Emmanuel Duvshani}
\date{\today}
\begin{document}
% \maketitle
\bigskip
(Date de l'import des données en base :\VAR{dateDernierExport})
\bigskip
\newcolumntype{y}{>{\columncolor{yellow}}l}
%% for cellule in listeCellules
\hypertarget{\VAR{cellule.dpt_im}}{\VAR{cellule.dpt_im }}
\bigskip
\begin{flushleft}
\begin{tabular}{ | y | }
\hline
%% for utilisateur in cellule.utilisateurs.all
\hyperlink{http://annuaire-entreprise.inetpsa.com/?action=exec_recherche_personne&identifiant=\VAR{utilisateur.cod_user}}{\VAR{utilisateur.cod_user}}-\VAR{utilisateur.lib_prenom}\VAR{utilisateur.lib_nom_usuel}
\hline
%% endfor
\end{tabular}
\end{flushleft}
\bigskip
%% endfor
\end{document}
Функция запускается в файле "views.py"
При использовании шаблона HTML:
enter code here
def index_cellules(request):
# Date de dernier export de la base Reflex
listeDateExports = DateExports.objects.all()
dateDernierExport = listeDateExports[0].date[:10]
# Liste des applications de la table Perimetre
listeApplications = Perimetre.objects.values_list('hdkqtap').all()
# Liste des cellules correspondant aux applications de la table Perimetre
listeCellules = Hdkqtif.objects.filter(hdkqtap__in=listeApplications).distinct().order_by('dpt_im')
template = loader.get_template('inforeflex_gener_html/index_cellules.html')
contexte = {
"dateDernierExport" : dateDernierExport,
"listeCellules" : listeCellules,
}
return HttpResponse(template.render(contexte))
При использовании шаблона TeX (с jinja):
def index_cellules(request):
# Date de dernier export de la base Reflex
listeDateExports = DateExports.objects.all()
dateDernierExport = listeDateExports[0].date[:10]
# Liste des applications de la table Perimetre
listeApplications = Perimetre.objects.values_list('hdkqtap').all()
# Liste des cellules correspondant aux applications de la table Perimetre
listeCellules = Hdkqtif.objects.filter(hdkqtap__in=listeApplications).distinct().order_by('dpt_im')
latex_jinja_env = jinja2.Environment(
block_start_string = '\BLOCK{',
block_end_string = '}',
variable_start_string = '\VAR{',
variable_end_string = '}',
comment_start_string = '\#{',
comment_end_string = '}',
line_statement_prefix = '%%',
line_comment_prefix = '%#',
trim_blocks = True,
autoescape = False,
loader = jinja2.FileSystemLoader('C:\\EMMANUEL\\inforeflex\\django\\inforeflex\\inforeflex\\templates\\inforeflex_gener_html')
)
template = latex_jinja_env.get_template('index_cellules.tex')
contexte = {
"dateDernierExport" : dateDernierExport,
"listeCellules" : listeCellules,
}
return template.render(dateDernierExport=dateDernierExport, listeCellules=listeCellules)
Ожидаемые результаты для каждой ячейкиОтформатированный список пользователей. фактический результат - это сообщение об ошибке, касающееся строки "%% for utilisateur in cellule.utilisateurs.all".Это полное сообщение об ошибке:
`* TypeError at / inforeflex_gener_html / cellules
Объект 'method' не повторяется
Метод запроса: GET URL запроса: http://localhost:8000/inforeflex_gener_html/cellules Версия Django: 2.2.2 Тип исключения: TypeError Значение исключения:
Объект 'method' не может быть повторен
Расположение исключения: C: \ EMMANUEL \ inforeflex \ django \ inforeflex \ inforeflex\ templates \ inforeflex_gener_html \ index_cellules.tex в коде шаблона верхнего уровня, строка 42 Исполняемый файл Python: C: \ Users \ edu04718 \ AppData \ Local \ Programs \ Python \ Python37-32 \ python.exe Версия Python: 3.7.3 Путь к Python:
['C: \ EMMANUEL \ inforeflex \ django \ inforeflex', 'C: \ Users \ edu04718 \ AppData \ Local \ Programs \ Python \ Python37-32 \ python37.zip', 'C: \Users \ edu04718 \ AppData \ Local \ Programs \ Python \ Python37-32 \ DLLs ',' C: \ Users \ edu04718 \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib ',' C: \ Users \ edu04718 \AppData \ Local \ Programs \ Python \ Python37-32 ',' C: \ Users \ edu04718 \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib\ site-packages ']
Серверное время: чт, 19 сентября 2019 г. 15:19:47 + 0000 * `
Примечание : строка 42 - это следующая строка вшаблон TeX:
%% for utilisateur in cellule.utilisateurs.all