CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=d4b1d98afc6cc0f4c171dd93; HttpOnly; Path=/; Secure
set-cookie: trac_session=375fcfa7c35fa1aca8bb9450; expires=Tue, 21 Oct 2025 05:46:03 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 05:46:03 GMT
x-served-by: cache-fra-etou8220076-FRA, cache-bom-vanm7210080-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753249563.475851,VS0,VE346
vary: Accept-Encoding
SafeSettingsContextProcessor – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
The following code will provide template access to your project settings. For security, it won't pass any setting with SECRET or PASSWORD in it.
Save as context_processors.py
inside your project root (or anything you like, really)
# To use, add the following line to settings.py: # TEMPLATE_CONTEXT_PROCESSORS = ('my_project.context_processors.settings',) # # Remember, you need to use RequestContext instead of Context in your views: # from django.template import RequestContext # return render_to_response('my_app/my_template.html', {'some_var': 'foo'}, # context_instance=RequestContext(request)) from django.views.debug import get_safe_settings class SafeSettings: def __init__(self): self._settings = None def __getattr__(self, name): # Lazy load of settings. if self._settings is None: self._settings = get_safe_settings() # get_safe_settings only returns upper case settings, so let's not worry # about case sensitivity. name = name.upper() try: return self._settings[name] except KeyError: # This method should return the (computed) attribute value or raise # an AttributeError exception. raise AttributeError def settings(request): return {'settings': SafeSettings()}
-- code by SmileyChris
Last modified
19 years ago
Last modified on Aug 13, 2006, 4:45:22 PM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.