https://docs.djangoproject.com/en/1.11/ref/csrf/#ajax 
<https://docs.djangoproject.com/en/1.11/ref/csrf/#ajax>

> On 15 Jun 2017, at 17:20, 李余通 <liyutong19961...@gmail.com> wrote:
> 
> Sorry,the message of Django CSRF and X-CSRFToken i can find is less.
> Can you give me an example to use requests or urllib2 and set "X-CSRFToken" 
> header to post form?
> Thank you very much!
> 
> 在 2017年6月15日星期四 UTC+8下午9:37:25,Александр Христюхин写道:
> You could set "X-CSRFToken" header, that would be enough. Why do you post 
> data manually though?
> 
>> On 15 Jun 2017, at 16:33, 李余通 <liyutong...@gmail.com <javascript:>> wrote:
>> 
>> Ture,my way is wrong,should i send cookies?
>> 
>> 在 2017年6月15日星期四 UTC+8下午9:29:17,Александр Христюхин写道:
>> CSRF token value is passed in Django's response headers.
>> And anyway, you're no supposed to post data like that. Do you do that in 
>> tests?
>> 
>>> On 15 Jun 2017, at 16:20, liyutong...@gmail.com <> wrote:
>>> 
>>> I uis this code to submit form
>>> ```python
>>> import requests
>>> 
>>> url = 'http://127.0.0.1:8000/contact/ <http://127.0.0.1:8000/contact/>'
>>> d = {'subject':'你好','email':'','message':'thank u'}
>>> r = requests.post(url,data = d)
>>> print(r.text)
>>> ```
>>> 
>>> but i don't has csrfmiddlewaretoken's values
>>> I try to use requests.get to get csrfmiddlewaretoken's values then post,it 
>>> also wrong,what should i do?
>>> 
>>> -- 
>>> 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...@googlegroups.com <>.
>>> To post to this group, send email to django...@googlegroups.com <>.
>>> Visit this group at https://groups.google.com/group/django-users 
>>> <https://groups.google.com/group/django-users>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/b2a43a6f-cbe1-4347-be28-5f298093dae8%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/b2a43a6f-cbe1-4347-be28-5f298093dae8%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>> For more options, visit https://groups.google.com/d/optout 
>>> <https://groups.google.com/d/optout>.
>> 
>> 
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users 
>> <https://groups.google.com/group/django-users>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/e4931b53-1006-457b-b48f-3e16917cc908%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/e4931b53-1006-457b-b48f-3e16917cc908%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout 
>> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/0fbf3f28-7af7-49e2-aee0-a961cabf1865%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/0fbf3f28-7af7-49e2-aee0-a961cabf1865%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/DC576B22-5996-4225-8E29-52601DDC5C95%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to