On 2/20/07, Michael Radziej <[EMAIL PROTECTED]> wrote:
> 'context processor' sounds more difficult than it is. That's how it's
> actually done:
>
> from django.conf import settings
>
> def processor(request):
> return {'MEDIA_URL': settings.MEDIA_URL}
>
> ... and then add it to TEMPLATE_CONTEXT_PROCESSORS.
Chiming in here, I think this also leads to clearer and more
maintainable code in the end. Suppose we implement, say, a
TEMPLATE_CONSTANTS setting, and you're using a bunch of apps; it ends
up looking like
TEMPLATE_CONSTANTS = {
'APP1_IMPORTANT_VALUE_1': 'foo',
'APP1_IMPORTANT_VALUE_2': 'bar',
'APP1_IMPORTANT_VALUE_3: 'baz',
'APP2_IMPORTANT_VALUE_1', 'quux',
'APP2_IMPORTANT_VALUE_2': 'blorgle',
'APP2_IMPORTANT_VALUE_3': 'flingle',
etc. That's going to get messy very quickly if you each app needs a
value or two in the constants and you've got more than one or two
apps. With context processors you get something like this:
TEMPLATE_CONTEXT_PROCESSORS = (
'app1.context_processors.stuff',
'app2.context_processors.stuff',
)
Which keeps your settings file cleaner, and also makes it easier to
make changes to individual apps; instead of having to remember to go
back and change the settings files of all the projects which used it
whenever you change a constant, you can just change one place -- the
context processor inside the app -- and have it work universally.
Since we keep getting requests for these specific settings, I think
it's probably time to get a 'media' context processor and add
MEDIA_URL, etc. through it.
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---