可以使用context processors来解决全局变量问题 https://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors
Writing your own context processors
A context processor has a very simple interface: It’s just a Python function that takes one argument, an HttpRequest object, and returns a dictionary that gets added to the template context. Each context processor must return a dictionary.
Custom context processors can live anywhere in your code base. All Django cares about is that your custom context processors are pointed-to by your TEMPLATE_CONTEXT_PROCESSORS setting.