Re: setlang using AJAX

2015-02-12 Thread Tiago Barufi
You could simply add 

csrfmiddlewaretoken: 
document.getElementsByName('csrfmiddlewaretoken')[0].value,

to the parameters on $.post. That would surely prevent the 403.


Em segunda-feira, 30 de maio de 2011 12:03:46 UTC-3, doktoreas escreveu:
>
> Thank you very much, for your help and your code. 
> The problem is that the POST request is missing the csrf_token and so 
> I have got a 403 Error. 
> Have you got the same problem? 
>
> Thx 
> Luca 
>
> On 30 Mag, 16:42, urukay  wrote: 
> > Hi Luca, 
> > 
> > this is what i had on my site: 
> > 
> > 
> > {% ifequal LANGUAGE_CODE 'sk' %} 
> > {% trans 
> 'Slovak' %} 
> >  title="{% trans 'English' %}">{% 
> > trans 'English' %} 
> > {% else %} 
> >  title="{% trans 'Slovak' %}">{% 
> > trans 'Slovak' %} 
> > {% trans 
> 'English' %} 
> > {% endifequal %} 
> >  
> >  
> > $('.language-bar a').click(function(){ 
> > $.post('/i18n/setlang/', 
> {language:$(this).attr('href').split('#') 
> > [1], next:"{{request.path}}" },function(data) 
> > {top.location.href="{{request.path}}";}); 
> > return false; 
> > }); 
> >  
> > 
> > Maybe it is not the best solution, but it's much nicer than 
> > selectboxes. It reloads the whole page,but it's not a problem adjust 
> > it to your needs. 
> > 
> > Radovan 
> > 
> > On 30. Máj, 16:19 h., Luca Casagrande  
> > wrote: 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > Hi Radovan, 
> > > this code should go on a web page before the real application. 
> > > Basically I'd like to have the user click on a flag representing the 
> > > language and load the real site with the appropriate language. 
> > 
> > > Thanks 
> > > L. 
> > 
> > > On 30 Mag, 15:30, urukay  wrote: 
> > 
> > > > hi, 
> > 
> > > > but you have to reload the whole page anyway or you want only part 
> of 
> > > > the page to be translated? 
> > > > There's a way to change language without form. 
> > 
> > > > R. 
> > 
> > > > On 30. Máj, 13:07 h., Luca Casagrande  
> > > > wrote: 
> > 
> > > > > Hello everybody, 
> > > > > I'd like to use an AJAX request without any form to change the 
> > > > > language of my site. 
> > > > > My problem is that I haven't found a way to avoid the csrf_token 
> > > > > error.. 
> > > > > How can I generate the token without any form? 
> > 
> > > > > The other way it to use setlang with a GET request but, according 
> to 
> > > > > docs, this seems no more possible. 
> > 
> > > > > Thanks for your support. 
> > > > > Luca

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87a93797-519f-4235-a3f0-cfe2f96422f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: setlang using AJAX

2011-05-30 Thread Kirill Spitsin
On Mon, May 30, 2011 at 08:03:46AM -0700, Luca Casagrande wrote:
> Thank you very much, for your help and your code.
> The problem is that the POST request is missing the csrf_token and so
> I have got a 403 Error.

https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax

-- 
Kirill Spitsin

-- 
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: setlang using AJAX

2011-05-30 Thread Luca Casagrande
Hi Radovan,
this code should go on a web page before the real application.
Basically I'd like to have the user click on a flag representing the
language and load the real site with the appropriate language.

Thanks
L.

On 30 Mag, 15:30, urukay  wrote:
> hi,
>
> but you have to reload the whole page anyway or you want only part of
> the page to be translated?
> There's a way to change language without form.
>
> R.
>
> On 30. Máj, 13:07 h., Luca Casagrande 
> wrote:
>
>
>
>
>
>
>
> > Hello everybody,
> > I'd like to use an AJAX request without any form to change the
> > language of my site.
> > My problem is that I haven't found a way to avoid the csrf_token
> > error..
> > How can I generate the token without any form?
>
> > The other way it to use setlang with a GET request but, according to
> > docs, this seems no more possible.
>
> > Thanks for your support.
> > Luca

-- 
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: setlang using AJAX

2011-05-30 Thread urukay
hi,

but you have to reload the whole page anyway or you want only part of
the page to be translated?
There's a way to change language without form.

R.

On 30. Máj, 13:07 h., Luca Casagrande 
wrote:
> Hello everybody,
> I'd like to use an AJAX request without any form to change the
> language of my site.
> My problem is that I haven't found a way to avoid the csrf_token
> error..
> How can I generate the token without any form?
>
> The other way it to use setlang with a GET request but, according to
> docs, this seems no more possible.
>
> Thanks for your support.
> Luca

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



setlang using AJAX

2011-05-30 Thread Luca Casagrande
Hello everybody,
I'd like to use an AJAX request without any form to change the
language of my site.
My problem is that I haven't found a way to avoid the csrf_token
error..
How can I generate the token without any form?

The other way it to use setlang with a GET request but, according to
docs, this seems no more possible.

Thanks for your support.
Luca

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