Rest of the example code
Template code:
\documentclass{article}
\begin{document}
\begin{center}
\section*{Table for {{date|date}} }
\begin{tabular}{
{% for _ in table.body.rows.0 %}|c{% endfor %}|
}
{# This is a comment #}
\hline
% This is another comment
\multicolumn{
{{table.headers.first.span}}
}{|c|}{ {{table.headers.first.value}} } &
\multicolumn{
{{table.headers.second.span}}
}{c|}{ {{table.headers.second.value}} } \\
\hline
\iffalse
This is a comment spanning several lines
\hline \fi
{% for row in table.body.rows %}
{% for cell in row %}{% if not cell == row.0 %} &
{% endif %} cell{{cell}} {% endfor %} \\
{% endfor %}
{% comment %}
This is another comment spanning several lines
\hline {% endcomment %}
\hline
\end{tabular}
\end{center}
\end{document}
We could combine the code from the django-tex
template with the following function based view to render the LaTeX document:
from django_tex.shortcuts import render_to_pdf
from datetime import date
def render_pdf(request):
table = {
'headers': {
'first': {
'span': 3,
'value': 'First Multicol',
},
'second': {
'span': 3,
'value': 'Second Multicol',
},
},
'body': {
'rows': [
[i for i in range(6)],
[i for i in range(6)],
[i for i in range(6)],
[i for i in range(6)],
[i for i in range(6)],
]
},
}
filename = 'filename.pdf'
template_name = 'path/to/template_name.pdf'
context = {
'date': date.today(),
'table': table,
}
return render_to_pdf(
request,
template_name,
context,
filename,
)
This would produce: