On 07/08/06 17:13, keukaman wrote:
> I'm getting tantalizingly close to being able to put a simple Django
> site online. Any help on this ticket will get me a long way toward
> getting there:
> 
> I have my media directories located at:
> 
> /home/username/media
>                                  ./img
>                                  ./css
>                                  ./js
> 
> I have my templates directory at:
> /home/username/templates
> 
> I have setup a subdomain called media.mydomain.com that points to
> /home/username/media
> 
> I updated my settings.py file so that
> MEDIA_ROOT = '/home/username/media/'
> MEDIA_URL = 'http://media.mydomain.com'
> 
> If I have a template called index.html, could someone show me the
> actual code in that template to:
> 
> 1. reference a stylesheet in the template
> 2. display a logo that is stored in media.mydomain.com/img
> 

The best way is to use template context processors as James Bennett 
explained nicely on his blog [1].

http://www.b-list.org/weblog/2006/06/14/django-tips-template-context-processors

Here's how I use it:

myproject/my_app/context_processors.py:
def settings(request):
     from django.conf import settings as config_settings
     d = {}
     try:
         for key in config_settings.TEMPLATE_SETTINGS:
             d[key] = getattr(config_settings, key, None)
     except AttributeError:
         if config_settings.DEBUG:
             raise
     return d


myproject/settings.py:
MEDIA_URL = 'http://media.mydomain.com/'

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
     'myproject.my_app.context_processors.settings',
)

# List all variables from settings.py that should be added to the
# RequestContext by the 'settings' context processor
TEMPLATE_SETTINGS = (
     'MEDIA_URL',
     'SITE_ID',
)


index.html:
...
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL 
}}css/screen.css" />
...
<img src="{{ MEDIA_URL }}img/logo.png" />
<p>The site id is {{ SITE_ID }}.</p>

hope this helps
cheers
Steven

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to