gpt4 book ai didi

django - 'WSGIRequest' 对象没有属性 'get'

转载 作者:行者123 更新时间:2023-12-04 05:38:11 25 4
gpt4 key购买 nike

我正在尝试使用 Django 创建登录表单。我正在创建一个 View 女巫将处理登录的获取和发布请求。

这是我如何设计它的:

class Login(View):
def get(self,request):
c = {}
c.update(csrf(request))
return render_to_response("login.html", c)
def post(self,request):
username = request.get('username','')
password = request.get('password','')
user = auth.authenticate(username = username, password = password)
if(user is not None):
auth.login(request,user)
return True
else:
return False

我可以得到这个表格,但是当我发帖时,我得到:
'WSGIRequest' object has no attribute 'get'

错误。设计此类 View 的正确方法是什么?

最佳答案

您应该使用 request.POST类似dict的对象:

username = request.POST.get('username','')
password = request.POST.get('password','')

关于django - 'WSGIRequest' 对象没有属性 'get',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28515470/

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