(2)常用模板(登录)

登录模板:参考https://blog.csdn.net/qq_35718410/article/details/52149894

HTML:注意提交数据type=“submit”,form action调转到下一个执行界面

{% load static from staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link href="/static/app1/css/create.css/"  rel="stylesheet"  type="text/css">
</head>
<body background="/static/app1/img/register.jpg"> {# 设置背景图片 #}
<div class="login">
<form action="adduser/" method="post">
    <div class="input_control">
        <input type="text" name="name_1" value="" id="btn1"
               class="form_input" placeholder="Enter your name here"/>
    </div>
    <div class="input_control">
        <input type="email" name="id_1" value=""  id="btn2"
               class="form_input" placeholder="Enter  your  Email  here"/>
    </div>
    <div class="input_control">
        <input type="password" name="pwd_1" value="" id="btn3"
               class="form_input" placeholder="Enter your key here"/>
    </div>
    <div class="input_control">
        {# submit的style在CSS引入时失败,故直接引入 #}
        <input type="submit"  class="form_input" value="注册"
               style="box-sizing: border-box;
  text-align:center;font-size:1.4em;height:2.7em;border-radius:4px;
  border:1px solid #98AFC7;color:#6a6f77;-web-kit-appearance:none;
  -moz-appearance: none;display:block;outline:0;padding:0 1em;
  text-decoration:none;width:100%;cursor: pointer"/>
    </div>
</form>
  </div>
</body>
</html>

 

CSS:

     /*===========表单居中==============*/
/*采用两个div,控制绝对位置和相对位置,使表单居中显示*/
.login{
         width:400px;
         height:280px;
         position:absolute;
         left: 50%;
         top: 50%;
         margin-left:-200px;
         margin-top:-140px;
         border:1px;
         align:center;
      }

/*=================优化input的样式==================*/
.input_control{
  width:360px;
  margin:20px auto;
}
/*===============text=====================*/
input[type="text"],#btn1{
  box-sizing: border-box;
  text-align:center;
  font-size:1.4em;
  height:2.7em;
  border-radius:4px;
  border:1px solid #c8cccf;
  color:#6a6f77;
  -web-kit-appearance:none;
  -moz-appearance: none;
  display:block;
  outline:0;
  padding:0 1em;
  text-decoration:none;
  width:100%;
}
input[type="text"]:focus{
  border:1px solid #ff7496;
}
/*==============Email=================*/
input[type="email"],#btn2{
  box-sizing: border-box;
  text-align:center;
  font-size:1.4em;
  height:2.7em;
  border-radius:4px;
  border:1px solid #c8cccf;
  color:#6a6f77;
  -web-kit-appearance:none;
  -moz-appearance: none;
  display:block;
  outline:0;
  padding:0 1em;
  text-decoration:none;
  width:100%;
}
input[type="email"]:focus{
  border:1px solid #ff7496;
}
/*=============password==============*/
input[type="password"],#btn3{
  box-sizing: border-box;
  text-align:center;
  font-size:1.4em;
  height:2.7em;
  border-radius:4px;
  border:1px solid #c8cccf;
  color:#6a6f77;
  -web-kit-appearance:none;
  -moz-appearance: none;
  display:block;
  outline:0;
  padding:0 1em;
  text-decoration:none;
  width:100%;
}
input[type="password"]:focus{
  border:1px solid #ff7496;
}

url配置:

from django.urls import path
from . import views
from django.conf.urls import url


#配置project下来的url
urlpatterns =[
   path ('createuser/',views.createuser),
   path('register/', views.register),
   path('register/adduser/', views.adduser),   #动态生成
]

views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

views.py

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

#创建添加user的视图
from .models import user
def register(request):
   return  render(request,'app1/register.html')

def createuser(request):
   return render(request, 'app1/createuser.html')

def adduser(request):
   # post获取表单数据并存入数据库
   name=request.POST.get("name_1")
   id=request.POST.get("id_1")
   pwd=request.POST.get("pwd_1")
   #print(name+id+pwd)
   if request.method == 'POST':
      user1= user.createuser(name, id,pwd)
      user1.save()
   return HttpResponse("XX")

 models.py

from django.db import models

# Create your models here.

#app1的模型
#,先注册,再登录用户,添加用户模型
class user(models.Model):
#定义元选项
   class Meta:
      db_table="user"
      ordering=['id']
#用户名、账号、密码、性别、关联好友
   uname =  models.CharField(max_length=20)
   uid   =  models.CharField(max_length=20)
   upwd  =  models.CharField(max_length=20)
#定义一个列表来表示关联,列表里面存在对应的id就表示关联,需要后面操作来添加列表的数据
#=====================================================
#创建一个类方法添加对象
   @classmethod
   def createuser(cls,name,id,pwd):
      user = cls(uname=name,uid=id,upwd=pwd)
      return  user

 

猜你喜欢

转载自blog.csdn.net/qq_40178878/article/details/86686693