类型'NoneType'的/ signup对象处的TypeError没有len()

时间:2020-05-26 01:08:04

标签: python django

我的观点:

class RegistrationView(View):
    def get(self,request):
        return render(request, 'accounts/signup.html')

    def post(self, request):
        context={
            'data':request.POST,
            'has_error':False
        }
        name = request.POST.get('name')
        username = request.POST.get('username')
        email = request.POST.get('email')
        password = request.POST.get('password')
        password1 = request.POST.get('password1')
        username = request.POST.get('username')

        if len(password)<8:
            messages.add_message(request,messages.ERROR, 'Password should be atleast 8 characters long !!!')
            context['has_error']=True

1 个答案:

答案 0 :(得分:0)

注意:请在表单输入字段中检出名称,它们是区分大小写的。在django中,它是Password而不是password,其他字段相同。

然后通过默认值'' ,以防找不到避免无

否则,在使用len()之前显式检查不是None

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