I think there are a few ways of doing this in previous messages, but
here's what has worked for me, using a custom context processor.

In settings,  I add whatever custom variables I want, including this:
APP_BASE = "http://www.example.com/";

I have an app called home, and in the views.py I put this:
---
"""
A request processor that returns dictionary to be merged into a
template context. Function takes the request object as its only
parameter
and returns a dictionary to add to the context.

These are referenced from the setting TEMPLATE_CONTEXT_PROCESSORS and
used by DjangoContext.
"""

from django.conf.settings import APP_BASE

def set_vars(request):
    """
    Returns custom context variables required by this app from
settings.py
    """
    context_extras = {}
    context_extras['APP_BASE'] = APP_BASE
    return context_extras

---------
You could add other custom variables to this.

In settings again, I added to...

TEMPLATE_CONTEXT_PROCESSORS = (
...
        "django.models.home.set_vars",
)

In the template use
<a href="{{ APP_BASE }}thing/somethingelse/">...

The one gotcha with this is you must remember to use DjangoContext in
your views:
    from django.core.extensions import DjangoContext as Context

But then you have to do that to use any of the template context
processors.

Derek

Reply via email to