It's not possible like this, of course. The template tags are
processed at the server, the javascript later at the client. What is
it you'd like to do? It's hard to help out if you don't tell us what
you're trying to achieve.
Matthias
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