我为用户注册和登录页面开发了名为“login”的django应用程序名称
login.views.py
def submitreport(request):
errors=[]
if request.method =='POST':
if not request.POST.get('m_id', ''):
errors.append('Enter a m_id.')
if request.POST.get('email') and '@' not in request.POST['email']:
errors.append('Enter a valid e-mail address.')
if not request.POST.get('passcode', ''): #this triggered even when i typed
errors.append('Enter password')
if not errors:
m_id= request.POST.get('id', '')
Email = request.POST.get('email', '')
password =request.POST.get('passcode','')
print(password)
user = User.objects.create_user(m_id,Email,password)
messages.success(request, "Successfully registered")
return HttpResponseRedirect('/')
return render(request, 'login/register.html',{'errors': errors})
register.html
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
</head>
<body>
{% if errors %}
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
<form action="{% url 'login:submitreport' %}" method="post">
<p>Machine id : <input type="text" name="m_id" value="{{ m_id }}"></p>
<p>e-mail (optional): <input type="text" name="email" value="{{ email }}"></p>
<p>password: <input type="password" name="psw" value="{{ passcode }}"></p>
<input type="submit" value="Submit">
</form>
</body>
</html>
答案 0 :(得分:0)
你应该在你看来:
password =request.POST.get('psw','')
不
password =request.POST.get('passcode','')