效果图:
class UserInfo(models.Model): username = models.CharField(max_length=32, verbose_name='用户名') password = models.CharField(max_length=32, verbose_name='密码')
def logon(request): if request.method == 'GET': return render(request, 'logon_page.html') if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') if username and password: user_obj = models.UserInfo.objects.create(username=username, password=password) return HttpResponse('注册成功') else: return HttpResponse('账号或密码不能为空')
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册页面</title> {% load static %} <link rel="stylesheet" href="{% static 'Bootstrap337/css/bootstrap.min.css' %}"> <script src="{% static 'Bootstrap337/js/bootstrap.min.js' %}"></script> </head> <body> <h1 class="text-center">注册页面</h1> <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <form action="" method="post"> <p>注册账号:<input type="text" class="form-control" name="username"></p> <p>注册密码:<input type="password" class="form-control" name="password"></p> <p><input type="submit" value="提交注册" class="btn btn-info btn-block"></p> </form> </div> </div> </div> </body> </html>