Sven Richter kirjoitti:
> Ok, i think i understand the problem now.
> So i have to hardcode the url in my javascript function?
> That was what i wanted to circumvent.

No you don't have to.

There is two ways, either you just use base URL like {% url url_name %} 
and send parameters as POST (or well, you can do GET params if you like 
to) or construct rest of the URL in JS.

Personally I'm always doing it with POST parameters in Ajax. It's just 
simpler that way.

One reason not to use hardcoded URL's is avoid modifying scripts when 
deploying. Specially when you start deploying same project many times to 
suburls it starts to come pretty valueble to have template resolving URL.

> On Sun, Aug 9, 2009 at 5:57 PM, Daniel Roseman <dan...@roseman.org.uk 
> <mailto:dan...@roseman.org.uk>> wrote:
> 
> 
>     On Aug 9, 4:43 pm, Sven Richter <sver...@googlemail.com
>     <mailto:sver...@googlemail.com>> wrote:
>      > Hi all,
>      >
>      > i wanted to know if it is possible to pass a Javascript variable to
>      > the url template tag?
>      >
>      > Like:
>      > <html>
>      > ...
>      > <script language="javascript">
>      > var param = 12;
>      > var url = {% url url_name param %}
>      > ...
>      >
>      > I've done a lot af googling but havent found anything.
>      >
>      > Greetings
>      > Sven
> 
>     How could this work? The template tag is resolved server-side when the
>     template is output, whereas the javascript runs client-side later.
> 
>     The best you could do would be to parse the output of the tag and
>     replace it dynamically with the javascript param, but since to do that
>     you'd have to know the format of the url, it sort of removes the point
>     of using the tag in the first place.
>     --
>     DR.

-- 
Jani Tiainen

--~--~---------~--~----~------------~-------~--~----~
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