Make templates more reusable by Improving template loading algorithm to avoid extending infinite recursion

[Ticket 15053](https://code.djangoproject.com/ticket/15053 "Ticket 15053")