Thursday, September 30, 2010

Re: Separating application media from project media

On 29/09/2010 13:58, Benedict Verheyen wrote:
> On 29/09/2010 13:13, David De La Harpe Golden wrote:
>> On 29/09/10 09:34, Benedict Verheyen wrote:
>>
>>> In my template i add this:
>>> <link rel="stylesheet" type="text/css" href="{{MEDIA_URL_CALLTRACKING}}/style/login.css" />
>>>
>>
>> (I'd favour prefix rather than suffix if you're going to pseudo-namespace)
>>
>> Did you introduce such a MEDIA_URL_CALLTRACKING variable into the
>> template context by any means? It's not automatic. For MEDIA_URL, the
>> value in your settings is propagated into the template context by
>> django.core.context_processors.media, which you'll see is a
>> TEMPLATE_CONTEXT_PROCESSORS entry in settings.py
>>
>> If you want to duplicate that functionality for another variable, it's
>> straightforward enough to write a template context processor to do that
>> if you want to, see source.
>>
>> http://code.djangoproject.com/browser/django/trunk/django/core/context_processors.py#L69
>>
>> n.b. template context processors only work for RequestContext contexts,
>> which not everything uses (obviously for your own apps you can just make
>> sure to use them).
>>
>> FWIW, that's not the pattern the admin contrib follows, it uses a
>> custom template tag library that includes a custom tag that resolves to
>> the admin media prefix, so its templates
>> do a
>> {% load adminmedia %} to load the tag library then they use
>> "{% admin_media_prefix %}blah/blah"
>>
>> http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templatetags/adminmedia.py
>>
>> I have no particular opinion on what approach is better, both work.
>
> Thanks,
>
>
> both seem solutions to what i'm trying to do. I'll try them out and report back
> if it works.
>
> Regards,
> Benedict

Hi,

i went for the template tag approach.
The template context processor would put an application specific variable available
for all other applications in this project and that didn't feel right.

The template tag allows for a certain variable to be available only to the application.
That's why i choose it.
Another benefit is that other developers see that you included something extra and thus
know about the variable. If you use a template context processor, the var is
auto magically added and a developer might miss the fact that this var is
available for use.
Of course you have documentation but the chances are that somebody misses it.

Regards,
Benedict


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment