On Mar 20, 6:16 am, Alfonso <allanhender...@gmail.com> wrote:
> Hi,
>
> Insanely simple answer here I think but I'm trying to sort some url
> errors in a mapping app.  Virtual earth requires an absolute url to
> the KML file django is generating for me and I can't seem to work out
> how to define that in the urls.py.  of course I can just prepend the
> site root to the VE javascript but who wants to do that for each
> page!  Also the site url will change so changing the urls in the JS is
> a hassle I don't want to deal with.
>
> url(r'^kml/popular_sites.kml','myproject.myapp.views.popular_sites',
> name="popular_sites"),
>
> When using the above with {% url popular_sites %} I get '/kml/
> popular_sites.kml' which V Earth doesn't like.  Is there a simple
> change in urls.py to get the full (I guess permalink) url 
> -http://mysite.com/kml/popular_sites? Perhaps in the associated view?

You could create a custom absolute_url tag whose structure is
something like this:

from django.template.defaultags import URLNode

class AbsoluteURLNode(URLNode):
    def render(self, context):
        url = super(AbsoluteURLNode, self).render(context)
        # prepend your protocol and hostname to
        # the relative url here
        return url

def absolute_url(parser, token):
    # copy the entire django.template.defaultags.url method
    # here and change the last line to
    return AbsoluteURLNode(viewname, args, kwargs, asvar)
absolute_url = register.tag(absolute_url)

-Rajesh D
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to