site url

114 views
Skip to first unread message

Kenneth Gonsalves

unread,
Oct 20, 2005, 5:43:04 AM10/20/05
to Django users
hi,
i know it must be somewhere, but cant find it. How do you refer to the
site url in a template? Say my css file is in
http://mysite.com/css/layout.css, to make this portable i would have to
make the template as:

{{ site_url }}/css/layout.css.
how do i do this?
--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

Andy Shaw

unread,
Oct 20, 2005, 7:26:06 AM10/20/05
to django...@googlegroups.com
Kenneth Gonsalves wrote:
> hi,
> i know it must be somewhere, but cant find it. How do you refer to the
> site url in a template? Say my css file is in
> http://mysite.com/css/layout.css, to make this portable i would have to
> make the template as:
>
> {{ site_url }}/css/layout.css.
> how do i do this?

Um... I don't know the actual answer to your question off the bat, but
you can use an absolute URI that doesn't contain the site name:

<link rel="stylesheet" type="text/css" href="/css/layout.css" />

Works for me...

-Andy

Kenneth Gonsalves

unread,
Oct 20, 2005, 8:21:50 AM10/20/05
to django...@googlegroups.com
On Thursday 20 Oct 2005 4:56 pm, Andy Shaw wrote:
> > {{ site_url }}/css/layout.css.
> > how do i do this?
>
> Um... I don't know the actual answer to your question off the bat,
> but you can use an absolute URI that doesn't contain the site name:

thing is that i have one copy of the app on my local machine and the
other on the production server. if this is portable i can test out on
my local machine and then just update on the server without changing
anything. The only difference between the two is the
'http://localhost/' part

Ian Holsman

unread,
Oct 20, 2005, 4:34:16 PM10/20/05
to django...@googlegroups.com
another approach might be to use something like the admin_media templatetag.
but now 'admin' is a app, you might be able to use the admin_media
templatetag directly.

(in this tag, MEDIA_URL is in the settings file and contains the URL
prefix.. so I would go something liike

{% load media %}
{% media_prefix %}css/myfunkystyle.css


this is basically the admin_media templatetag but using a different setting.
--0<---
from django.core import template

class MediaPrefixNode(template.Node):
def render(self, context):
try:
from django.conf.settings import MEDIA_URL
except ImportError:
return ''
return MEDIA_URL

def media_prefix(parser, token):
"""
{% media_prefix %}
"""
return MediaPrefixNode()

template.register_tag('media_prefix', media_prefix)


--
I...@Holsman.net -- ++61-3-9877-0909
If everything seems under control, you're not going fast enough. -
Mario Andretti

Reply all
Reply to author
Forward
0 new messages