rearrange for and try/except nesting in settings context processor