gpt4 book ai didi

python - “WSGIRequest”对象不可订阅

转载 作者:太空狗 更新时间:2023-10-29 14:46:26 27 4
gpt4 key购买 nike

我在 views.py 文件中的这个函数中遇到了这个错误。这很令人困惑,因为我不知道“WSGIRequest”是什么,也不知道它为什么给我带来问题。我知道我有一个名为“newUser”的变量,因为当我取出那一行时,print(request.POST) 行将其打印出来。

def AddNewUser(请求):

a=AMI()
if(request.method == "POST"):
print(request.POST)
print(request["newUser"])
csrfContext = RequestContext(request)
return render_to_response("ac/AddNewUser.html", csrfContext)

`

为什么会出现此错误?

最佳答案

It means that WSGIRequest does not implement __getitem__ .您正试图将 HttpRequest 对象视为字典,但事实并非如此。如果你想访问这个 newUser 变量,请使用 POST 对象,它实现了一个类似字典的接口(interface):

request.POST['newUser']

You'd do well to peruse the Django docs in situations like this.

关于python - “WSGIRequest”对象不可订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5922958/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com