Fix for #22232

Fix for #22232 preventing RuntimeError Maximum Recursion Depth Exceeded when a template extends itself.
https://code.djangoproject.com/ticket/22232