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.
I think a docstring like this would be helpful: "Test render_to_string() when makomiddleware has not initialized the threadlocal REQUEST_CONTEXT.context,"