class RegisterTest(View):
def get(self, request):
form = RegisterForm()
return render(request, 'form_session/register.html', context={'form': form})
def post(self, request):
form = RegisterForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
pwd = form.cleaned_data.get('password')
pwd_confirm = form.cleaned_data.get('password_confirm')
email = form.cleaned_data.get('email')
if pwd == pwd_confirm:
UserModel.objects.create(username=username, password=pwd, email=email)
return HttpResponse('注册成功,欢迎您使用我们的网站!')
else:
return HttpResponse('注册失败,您输入的两次密码不一致!')
else:
return HttpResponse('注册失败,请输入合法的数据!')
注册页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册页面</title>
</head>
<body>
<form action="{% url 'register' %}" method="post">
{% csrf_token %}
{
{{ form.as_p }}
<input type="submit" value="注册">
</form>
</body>
</html>
注册页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册页面</title>
</head>
<body>
<form action="{% url 'register' %}" method="post">
{% csrf_token %}
{
{{ form.as_p }}
<input type="submit" value="注册">
</form>
</body>
</html>
|