Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在/accounts/signup/'处出现多值错误;密码';_Python_Django - Fatal编程技术网

Python 在/accounts/signup/'处出现多值错误;密码';

Python 在/accounts/signup/'处出现多值错误;密码';,python,django,Python,Django,我是django python新手,在注册过程中遇到了这个奇怪的错误 请让我知道我哪里做错了 这是我在views.py中的代码: if request.method=='POST': #SignUp if request.POST['password1'] == request.POST['password2']: try: user = User.objects.get(username = reques

我是django python新手,在注册过程中遇到了这个奇怪的错误

请让我知道我哪里做错了

这是我在views.py中的代码:

if request.method=='POST':
        #SignUp
        if request.POST['password1'] == request.POST['password2']:

            try:
                user = User.objects.get(username = request.POST.get('username1'))
                return render(request, 'accounts/signup.html', {'error':'username is already taken'})

            except User.DoesNotExist:
                user = User.objects.create_user(username=request.POST['username1'], password=request.POST['password'])
                auth.login(request, user)
                return redirect('home')

    else:
        #enter info
        return render(request, 'accounts/signup.html')
如果我输入
user=request.POST.get('username1')
则无论输入什么,我都会收到“username ready take”消息

我的html代码:

<form method="POST" action="{% url 'signup' %}" class="form" autocomplete="off">

        {% csrf_token %}
          <div class="form__group">
              <input type="text" placeholder="username" name="username1" class="form__input" id="username1" autocomplete="off"/>
          </div>

          <div class="form__group" autocomplete="off">
              <input type="email" placeholder="email" name="email" class="form__input" autocomplete="off"/>
          </div>

          <div class="form__group">
              <input type="password" placeholder="Password" name="password1" class="form__input" />
          </div>

          <div class="form__group">
              <input type="password" placeholder="Confirm Password" name="password2" class="form__input" />
          </div>

          <input class="btn btn-primary" type="submit" value="signup!"/>
      </form>
我已经花了好几个小时,但我仍然不知道我做错了什么。 任何帮助都将不胜感激

if request.method=='POST':
        #SignUp
        if request.POST['password1'] == request.POST['password2']:

            try:
                user = User.objects.get(username = request.POST.get('username1'))
                return render(request, 'accounts/signup.html', {'error':'username is already taken'})

            except User.DoesNotExist:
                user = User.objects.create_user(username=request.POST['username1'], password=request.POST['password1'])
                auth.login(request, user)
                return redirect('home')

    else:
        #enter info
        return render(request, 'accounts/signup.html')

错误:如果查看try块,您尝试获取用户名,那么您没有使用此用户名执行任何操作,然后在render方法中,您通过分配信息发送错误消息。因此,在模板文件上,它显示错误消息,因为您将其作为默认消息发送。

我获得了“用户名”无论我输入的是什么,都已接收“消息”。
因为它不会引发异常。请查看
user
的值是什么。|至于“password”的错误-您有password1和password2,而不是“password”.哦,是的。我完全错过了。我只是觉得发帖请求有点问题,错过了一个明显的问题。是的,我做了一件很糟糕的事,浪费了很多时间。谢谢你帮我节省了剩下的时间。
if request.method=='POST':
        #SignUp
        if request.POST['password1'] == request.POST['password2']:

            try:
                user = User.objects.get(username = request.POST.get('username1'))
                return render(request, 'accounts/signup.html', {'error':'username is already taken'})

            except User.DoesNotExist:
                user = User.objects.create_user(username=request.POST['username1'], password=request.POST['password1'])
                auth.login(request, user)
                return redirect('home')

    else:
        #enter info
        return render(request, 'accounts/signup.html')