小编Maq*_*q T的帖子

类型错误:无法解包不可迭代的 bool 对象

当我运行代码时,它会重定向并显示

TypeError at /accounts/register cannot unpack non-iterable bool object
Run Code Online (Sandbox Code Playgroud)

问题是当我将以下条件放在我的代码中时

User.objects.filter(username==username).exists():

User.objects.filter(email=email).exists():

Run Code Online (Sandbox Code Playgroud)

请帮忙

from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth



# Create your views here.

def register(request):

    if request.method == 'POST':
        last_name = request.POST['Last_name']
        first_name = request.POST['first_name']
        username = request.POST['username']
        email = request.POST['email']
        password1 = request.POST['password1']
        password2 = request.POST['password2']

        if password1==password2:
            if User.objects.filter(username==username).exists():
                print("username taken")
            elif User.objects.filter(email=email).exists():
                print('email exists')
            else:
                user = User.objects.create_user(username=username,password=password1,email=email,first_name=first_name,last_name=last_name)
                user.save()
                print('User Created')
        else:
            print('password doesnt match')

        return redirect('/')


    else:
        return render(request,'accounts/register.html')

Run Code Online (Sandbox Code Playgroud)

错误

TypeError: …
Run Code Online (Sandbox Code Playgroud)

python django django-views python-3.x python-requests

4
推荐指数
1
解决办法
1万
查看次数