我正在使用 django 创建用户注册。我用我的视图寄存器创建了一个简单的 HTML 文件。但是当我点击提交时,它给了我一个错误:
email_name, domain_part = email.strip().split('@', 1)
AttributeError: 'tuple' object has no attribute 'strip'
我的HTML:
<form action="register" method="post">
{% csrf_token %}
<input type="text" name="first_name" placeholder="Enter ur nem"><br>
<input type="text" name="last_name" placeholder="Enter ur surname"><br>
<input type="email" name="email" placeholder="Enter ur email"><br>
<input type="text" name="username" placeholder="Enter ur Usetrname"><br>
<input type="password" name="password1" placeholder="Enter ur password"><br>
<input type="password" name="password2" placeholder="Enter again your password"><br>
<input type="submit"> </div>
我的看法:
from django.contrib.auth.models import User , auth
def register(request):
if request.method == 'POST':
first_name= request.POST['first_name'],
last_name= request.POST['last_name'],
email= request.POST['email'],
password1 = request.POST['password1'],
password2= request.POST['password2'],
username= request.POST['username'],
if password1 == password2:
if User.objects.filter(username=username).exists():
print('usernem taken')
else:
myuser= User.objects.create_user(username=username, password = password1, email= email,
first_name = first_name, last_name= last_name)
myuser.save();
print ('user saved')
else:
print('passwords do not match')
return redirect ('/')
莫回无
相关分类