【发布时间】:2017-11-22 21:00:30
【问题描述】:
我在 python 3 中使用requests 库。
我的目标是一个两步过程:
- 从 python 程序向我的 Django 应用发送 post 请求。
- 通过使用在所述 Django 应用中发送的信息创建一个新的数据库条目来处理该发布请求。
我认为第一部分已经正确设置,开发服务器注册了 POST 请求。但是,我在执行第二步时遇到了一些问题。
我创建了一个特殊的 url 和 html 模板,只是为了查看在我发出 POST 请求后是否有任何东西被拾取。视图以这种方式处理:
def new_instance(request):
instance = 'Nothing picked up!'
if request.method == 'POST':
post = request.POST['ID']
instance = IDInstance(id=post)
instance.save()
return render(
request,
'viewpage.html',
context = {'instance':instance})
但是,实例变量和我的数据库都没有更新。
正在发出的请求如下所示:
Info = {'ID':'23234234'}
r = requests.post(domain,data=Info)
【问题讨论】:
标签: python django django-rest-framework django-views python-requests