Django在发送POST请求时返回403错误 [英] Django returns 403 error when sending a POST request

查看:265
本文介绍了Django在发送POST请求时返回403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用以下Python代码向我的Django网站发送POST请求时,我得到403:Forbidden错误。

when I'm using following Python code to send a POST request to my Django website I'm getting 403: Forbidden error.

url = 'http://www.sub.domain.com/'
values = { 'var': 'test' }

try:
    data = urllib.urlencode(values, doseq=True)
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    the_page = response.read()
except:
    the_page = sys.exc_info()
    raise

当我'打开任何其他网站它正常工作。
domain.com也是Django网站,它也正常工作。
我认为,这是Django配置问题,任何人都可以告诉我应该怎么做来提供对我的脚本的访问?

When I'm opening any other website it works properly. domain.com is Django website too, and it works properly too. I think, that's Django config problem, can anyone tell me what should I do to provide access to my script?

推荐答案

p>您发布的视图是否具有Django表单?如果是这样,我想知道是否给出了一个csrf错误。我认为这表现为403.在这种情况下,您需要添加{{csrf_token}}标签。只是一个想法。

Does the view that you are posting to have a Django Form on it? If so, I wonder if it's giving a csrf error. I think that manifests itself as a 403. In that case, you'd need to add the {{ csrf_token }} tag. Just a thought.

这篇关于Django在发送POST请求时返回403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆