Re: javascript variable in url resolver template tag

2009-08-10 Thread Jani Tiainen

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  > wrote:
> 
> 
> On Aug 9, 4:43 pm, Sven Richter  > wrote:
>  > Hi all,
>  >
>  > i wanted to know if it is possible to pass a Javascript variable to
>  > the url template tag?
>  >
>  > Like:
>  > 
>  > ...
>  > 

Re: javascript variable in url resolver template tag

2009-08-10 Thread Sven Richter
Ok, thank you very much, thats how i am gonna do it.
I just didnt think about the fact that django is being done on
the server side and the script on the client side.


Greetings
Sven

On Sun, Aug 9, 2009 at 8:20 PM, Daniel Roseman wrote:

>
> On Aug 9, 4:59 pm, Sven Richter  wrote:
> > I am looking for a rating function AJAX style.
> > So what i am trying to do is the following:
> >
> > Click on a link  > register a Jquery function to call on that click with:
> > $('a#vote_pos').click(rate_it);
> > and then in rate_it call the url rate with two paramaters int entry and
> > string pos_neg
> > like
> > $.ajax( {type:"POST", url:/entry/rate/pos_neg, ...
> > and i wanted to build the url with the url tag like:
> > url:{% url rate entry pos_neg %}
> >
> > Sven
> >
>
> Rather than having a dynamic URL with parameters, you'll just have to
> make the parameters part of the POST. So you can still use the url tag
> at render time to output the URL, but instead of it being /entry/5/
> rate/positive/ it should just be eg /entry/rate/, and the values for
> rate and pos_neg are keys in the POST.
> --
> DR.
> >
>

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



Re: javascript variable in url resolver template tag

2009-08-09 Thread Daniel Roseman

On Aug 9, 4:59 pm, Sven Richter  wrote:
> I am looking for a rating function AJAX style.
> So what i am trying to do is the following:
>
> Click on a link  register a Jquery function to call on that click with:
> $('a#vote_pos').click(rate_it);
> and then in rate_it call the url rate with two paramaters int entry and
> string pos_neg
> like
> $.ajax( {type:"POST", url:/entry/rate/pos_neg, ...
> and i wanted to build the url with the url tag like:
> url:{% url rate entry pos_neg %}
>
> Sven
>

Rather than having a dynamic URL with parameters, you'll just have to
make the parameters part of the POST. So you can still use the url tag
at render time to output the URL, but instead of it being /entry/5/
rate/positive/ it should just be eg /entry/rate/, and the values for
rate and pos_neg are keys in the POST.
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: javascript variable in url resolver template tag

2009-08-09 Thread Sven Richter
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.

Sven

On Sun, Aug 9, 2009 at 5:57 PM, Daniel Roseman wrote:

>
> On Aug 9, 4:43 pm, Sven Richter  wrote:
> > Hi all,
> >
> > i wanted to know if it is possible to pass a Javascript variable to
> > the url template tag?
> >
> > Like:
> > 
> > ...
> > 

Re: javascript variable in url resolver template tag

2009-08-09 Thread Sven Richter
I am looking for a rating function AJAX style.
So what i am trying to do is the following:

Click on a link  wrote:

>
> On Sun, Aug 9, 2009 at 5:43 PM, Sven Richter
> wrote:
> > Hi all,
> >
> > i wanted to know if it is possible to pass a Javascript variable to
> > the url template tag?
> >
> > Like:
> > 
> > ...
> > 

Re: javascript variable in url resolver template tag

2009-08-09 Thread Daniel Roseman

On Aug 9, 4:43 pm, Sven Richter  wrote:
> Hi all,
>
> i wanted to know if it is possible to pass a Javascript variable to
> the url template tag?
>
> Like:
> 
> ...
> 

Re: javascript variable in url resolver template tag

2009-08-09 Thread Matthias Kestenholz

On Sun, Aug 9, 2009 at 5:43 PM, Sven Richter wrote:
> Hi all,
>
> i wanted to know if it is possible to pass a Javascript variable to
> the url template tag?
>
> Like:
> 
> ...
>