Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Library of context processors.
4"""
6# Imports
8from django.conf import settings
10# Exports
12__all__ = (
13 "settings_in_context",
14)
16# Processors
19# noinspection PyUnusedLocal
20def settings_in_context(request):
21 """Insert certain Django settings into the context.
23 :param request: The request instance is not used.
24 :type: request: object
26 :rtype: dict
28 To identify the settings to be included in the request context, use the ``SETTINGS_IN_CONTEXT`` in your
29 ``settings.py`` file.
31 .. code-block:: py
33 COPYRIGHT_NAME = "Pleasant Tents, LLC"
35 MENU_ITEMS = [
36 ("home", "Home"),
37 ("dashboard", "Dashboard"),
38 ("profile", "Profile"),
39 ]
41 SITE_TITLE = "Example Site"
43 SUPERDJANGO_SETTINGS_IN_CONTEXT = [
44 "COPYRIGHT_NAME",
45 "MENU_ITEMS",
46 "SITE_TITLE",
47 ]
49 """
50 context = dict()
52 if not hasattr(settings, "SUPERDJANGO_SETTINGS_IN_CONTEXT"):
53 return context
55 names = getattr(settings, "SUPERDJANGO_SETTINGS_IN_CONTEXT")
57 for name in names:
58 try:
59 context[name] = getattr(settings, name)
60 except AttributeError:
61 context[name] = None
63 return context