I need to compile a .tex file twice with django_tex in order for the table of contents to load correctly. Is there a way to tell the interpreter in django_tex to run the compiler twice (I use pdflatex)??

Code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}


\begin{document}


\tableofcontents
\section{Introduction}
Introduction text.

\section{Second section}
Second section text.

\end{document}

django_tex seems to support latexmk, which will (amongst many other useful things, like running bibliography tools) automatically determine the required number of *tex runs.

To use this, you can follow the advice from https://github.com/weinbusch/django-tex/pull/5#issuecomment-447030408 and add

LATEX_INTERPRETER='latexmk -pdf'

to your settings.py.