Fix getting attribute from local thread.

When using thread-locals, we have to check whether the attribute of the thread local is set before using it.
Todo so always use hasattr or getattr.
Template rendering should work as long as it does not depend on any property that is included into the context from request objects.