Fix 500 template processing error

The 500.html template inherits base.html, which fails to process if the settings are not in the context.
This patch fixes it for most internal error cases, but it might be better to consider writing a simpler 500 template which does not require anything extra.