Django

Code

Ticket #3818 (closed: wontfix)

Opened 3 years ago

Last modified 8 months ago

Expose chosen settings to default context processor.

Reported by: ciantic@mbnet.fi Assigned to: adrian
Milestone: Component: Core framework
Version: SVN Keywords: expose_settings
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Gives user an ability to expose wanted settings to the default context processors, and when you control it from settings.py the only security risk is: stupid settings creator. Also it gives you control what to expose, if in future user might want to expose something else from there too.

settings.py: EXPOSE_SETTINGS = ('MEDIA_URL', 'ADMIN_MEDIA_PREFIX', 'LANGUAGE_CODE') It could be set by default to that.

There is no point to write multiple settings reading context processors, this is the settings context processor. If your application needs some other setting, then you expose it to the app.

Attachments

context_processors.diff (420 bytes) - added by ciantic@mbnet.fi on 03/25/07 17:46:01.
exposed context processor that handles reading of settings in context wise
context_settings.diff (1.1 kB) - added by m@mihasya.com on 07/26/09 14:08:24.
context processor for exposing settings in templates.

Change History

03/25/07 17:46:01 changed by ciantic@mbnet.fi

  • attachment context_processors.diff added.

exposed context processor that handles reading of settings in context wise

03/25/07 18:32:47 changed by SmileyChris

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

It's come up before, but this is a slightly different take.

03/27/07 17:33:19 changed by adrian

  • status changed from new to closed.
  • resolution set to duplicate.

Duplicate of #1278, which has been marked as a wontfix.

07/26/09 14:07:56 changed by m@mihasya.com

  • status changed from closed to reopened.
  • resolution deleted.

I don't think this is a duplicate of the MEDIA_URL ticket.

I think that it would simplify some development scenarios to be able to expose selected settings in the templates instead of having to write one-off context processors for every single one. This seems particularly useful for people who have custom settings. My usecase for this is a Google Analytics ID - I don't want GA to fire while I'm doing testing on my dev machine, so my dev settings.py has GA_ID set to "FOO" while the prod on has the real ID, and in my template I simply have {{ settings.GA_ID }}

I'm attaching a patch that is similar to the original one, with two differences: 1. settings are placed in a context dict named 'settings' to avoid collisions and to improve readability, so a setting would be accessed from the template as {{ settings.FOO }} 2. I've added the suggested defaults to global_settings.py

07/26/09 14:08:24 changed by m@mihasya.com

  • attachment context_settings.diff added.

context processor for exposing settings in templates.

07/26/09 19:10:55 changed by russellm

  • status changed from reopened to closed.
  • resolution set to wontfix.

This was marked Wontfix for a reason, and your patch doesn't address that reason.

The solution to every problem isn't "add a new setting". In this case, the solution is "write your own context processor".


Add/Change #3818 (Expose chosen settings to default context processor.)




Change Properties
Action