语法“cellue.usilizateurs.all”在Django HTML模板中有效,但在Django TeX模板中无效

2024-09-19 23:41:39 发布

您现在位置:Python中文网/ 问答频道 /正文

语法“cellue.usilizateurs.all”可用于HTML Django模板,但不能用于TeX Django模板

使用HTML Django模板,它会在WEB浏览器中显示的结果HTML文件中显示每个单元格(“Cellle”)的用户列表(法语为“用户列表”)

使用TeX Django模板,我在WEB浏览器中收到以下错误消息:

“方法”对象不可编辑

以下是不同的代码片段:

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)

对于每个单元格,预期结果是格式化的用户列表。 实际结果是一条关于行“%%代表Cellle.Utisulateurs.all中的Utisulateur”的错误消息。这是完整的错误消息:

` */inforeflex\u gener\u html/cellles处的类型错误

“方法”对象不可编辑

请求方法:获取 请求URL:http://localhost:8000/inforeflex_gener_html/cellules Django版本:2.2.2 异常类型:TypeError 异常值:

“方法”对象不可编辑

异常位置:C:\EMMANUEL\inforeflex\django\inforeflex\inforeflex\templates\inforeflex\u gener\u html\index\u cellles.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']

服务器时间:2019年9月19日星期四15:19:47+0000* `

备注:第42行是TeX模板中的以下行:

%% for utilisateur in cellule.utilisateurs.all

Tags: in模板varhtmldealldesutilisateur