Update middleware.py

LUN-1869: Make sure the default templates for the current request are set (even if 404 is raised).