[英]'Attribute Error/ function' object has no attribute 'objects' in Django
I am trying to login but getting this error 'function' object has no attribute 'objects'
, here is my view function,我正在尝试登录,但收到此错误'function' object has no attribute 'objects'
,这是我的观点 function,
def login(request):
if request.method=='POST':
email=request.POST['email']
password=request.POST['password']
if register.objects.filter(email=email,password=password).exists(): // Error at this line
request.session['login'] = email
return render(request,'user_dashboard.html',)
messages.info(request,'Login Success.....!')
else:
messages.warning(request,'Invalid Credentials....!')
return redirect('/login')
else:
return render(request,'login.html',)
The database contains valid credentials, please tell me where I am going wrong.数据库包含有效凭据,请告诉我哪里出错了。
If Register
is a database model (note that it would normally be declared with a capital letter), then Register.objects.all()
is the way to access all the objects.如果Register
是一个数据库 model(注意它通常用大写字母声明),那么Register.objects.all()
是访问所有对象的方法。 So your code could be:所以你的代码可能是:
if Register.objects.all().filter(email=email,password=password).exists():
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.