当前位置:   article > 正文

【Python】flask实现登录注册_flask登录注册

flask登录注册

一、jinjia2

1、控制结构

控制结构 Flask中的Jinja2模板提供了多种控制结构,通过这些控制结构可以改变模板的渲染过程。例如,下面展示的条件控制语句。


2、使用flask成功渲染到模板

【首先你要】

  1. 首先要创建一个templates目录,这里面放想要渲染到的html页面,再创建一个与templates目录同级py文件,py文件是渲染的效果;也就是说,py文件里是"骨架",templates里面的html文件是“血肉”,最终实现的效果;
  2. 导入Flask包

  3. 创建一个Flask对象

  4. 声明路由,只由声明一个路由才能访问到页面

    1. 在该路由下定义一个函数,将你想呈现的效果封装在这个函数里,在函数的最后一行return render_template

  5. 想要渲染成功必须使用

    render_template('index.html', title='hello world', list2=list1, my_list=my_list)

    将title,list2,render_template这三个变量的内容渲染到index.html页面中

  6. 定义过滤器,也就是一个函数

  7. 注册过滤器

    1. # 第一个参数是函数名,第二个是过滤器的名字,可在所有模板上使用这个函数
    2. app.add_template_filter(do_listreverse, 'listreverse')

  8. 运行Flask对象


【举个栗子】 

main.py

  1. from turtle import title
  2. from flask import Flask, render_template
  3. app = Flask(__name__)
  4. @app.route('/')
  5. def index():
  6. list1 = list(range(10))
  7. my_list = [
  8. {'id': 1, 'value': '我爱工作'},
  9. {'id': 2, 'value': '工作使人快乐'},
  10. {'id': 3, 'value': '沉迷工作无法自拔'},
  11. {'id': 4, 'value': '日渐消瘦'},
  12. {'id': 5, 'value': '以梦为马,不负韶华'}, ]
  13. # 将title,list2,render_template这三个变量的内容渲染到index.html页面中
  14. return render_template('index.html', title='hello world', list2=list1, my_list=my_list)
  15. # 自定义过滤器
  16. def do_listreverse(aa):
  17. temp_li = list(aa)
  18. temp_li.reverse() # 将列表反转
  19. return temp_li
  20. # 注册过滤器
  21. # 第一个参数是函数名,第二个是过滤器的名字,可在所有模板上使用这个函数
  22. app.add_template_filter(do_listreverse, 'listreverse')
  23. if __name__ == '__main__':
  24. app.run()

index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <!--接收从main.py传递的参数-->
  11. <!--通过listreverse过滤器将传递过来的参数反转并且转成大写-->
  12. <h1>{{title | listreverse | upper}}</h1>
  13. <br>
  14. <!--无序列表,ol是有序列表-->
  15. <ul>
  16. <!--# 使用for循环遍历传过来的参数-->
  17. {% for item in my_list %}
  18. <!--# 使用列表标签将内容一行一行显示,在main.py里mylist是一个大列表嵌套很多小的字典,其中id是k值,value是v值-->
  19. <li>{{item.id}}----{{item.value}}</li>
  20. {% endfor %}
  21. </ul>
  22. <ul>
  23. {% for item in my_list %}
  24. <!--# loop是jinjia2里的内置循环变量,loop.index是从1开始升序(循环迭代)-->
  25. {% if loop.index == 1 %}
  26. <li style="background-color: red;">{{loop.index}}----{{item.get('value')}}</li>
  27. {% elif loop.index == 2 %}
  28. <li style="background-color: gray;">{{loop.index}}----{{item.get('value')}}</li>
  29. {% elif loop.index == 3 %}
  30. <li style="background-color: blue;">{{loop.index}}----{{item.get('value')}}</li>
  31. {% else %}
  32. <li style="background-color: yellow;">{{loop.index}}----{{item.get('value')}}</li>
  33. {% endif %}
  34. {% endfor %}
  35. </ul>
  36. </body>
  37. </html>

 

二、简单的登录成功后跳转到指定页面:

main2.py

  1. from turtle import title
  2. import requests
  3. from flask import Flask, render_template, request, redirect, url_for, flash, session
  4. app = Flask(__name__)
  5. # 添加会话一定要设置密钥
  6. app.secret_key = 'asdffbgsc'
  7. @app.route('/')
  8. def index():
  9. list1 = list(range(10))
  10. my_list = [
  11. {'id': 1, 'value': '我爱工作'},
  12. {'id': 2, 'value': '工作使人快乐'},
  13. {'id': 3, 'value': '沉迷工作无法自拔'},
  14. {'id': 4, 'value': '日渐消瘦'},
  15. {'id': 5, 'value': '以梦为马,不负韶华'}, ]
  16. # 将title,list2,render_template这三个变量的内容渲染到index.html页面中
  17. return render_template('index.html', title='hello world', list2=list1, my_list=my_list, username=session.get('username'), password=session.get('password'))
  18. # 自定义过滤器
  19. def do_listreverse(aa):
  20. temp_li = list(aa)
  21. temp_li.reverse() # 将列表反转
  22. return temp_li
  23. @app.route('/login', methods=['GET', 'POST'])
  24. def login():
  25. if request.method == 'POST':
  26. username = request.form.get('username')
  27. password = request.form.get('password')
  28. if username == 'admin' and password == '123':
  29. print("登录成功!")
  30. # 设置会话,拿到全局的内容
  31. session['username']=username
  32. session['password'] =password
  33. return redirect('/')
  34. # else:
  35. # flash("用户名或密码错误")
  36. return render_template('login.html')
  37. # 注册过滤器
  38. # 第一个参数是函数名,第二个是过滤器的名字,可在所有模板上使用这个函数
  39. app.add_template_filter(do_listreverse, 'listreverse')
  40. if __name__ == '__main__':
  41. app.run(debug=True)

login.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. a {
  13. text-decoration: none;
  14. }
  15. input,
  16. button {
  17. background: transparent;
  18. border: 0;
  19. outline: none;
  20. }
  21. body {
  22. height: 100vh;
  23. background: linear-gradient(#141e30, #243b55);
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. font-size: 16px;
  28. color: #03e9f4;
  29. }
  30. .loginBox {
  31. width: 400px;
  32. height: 364px;
  33. background-color: #0c1622;
  34. margin: 100px auto;
  35. border-radius: 10px;
  36. box-shadow: 0 15px 25px 0 rgba(0, 0, 0, .6);
  37. padding: 40px;
  38. box-sizing: border-box;
  39. }
  40. h2 {
  41. text-align: center;
  42. color: aliceblue;
  43. margin-bottom: 30px;
  44. font-family: 'Courier New', Courier, monospace;
  45. }
  46. .item {
  47. height: 45px;
  48. border-bottom: 1px solid #fff;
  49. margin-bottom: 40px;
  50. position: relative;
  51. }
  52. .item input {
  53. width: 100%;
  54. height: 100%;
  55. color: #fff;
  56. padding-top: 20px;
  57. box-sizing: border-box;
  58. }
  59. .item input:focus+label,
  60. .item input:valid+label {
  61. top: 0px;
  62. font-size: 2px;
  63. }
  64. .item label {
  65. position: absolute;
  66. left: 0;
  67. top: 12px;
  68. transition: all 0.5s linear;
  69. }
  70. .btn {
  71. padding: 10px 20px;
  72. margin-top: 30px;
  73. color: #03e9f4;
  74. position: relative;
  75. overflow: hidden;
  76. text-transform: uppercase;
  77. letter-spacing: 2px;
  78. left: 35%;
  79. }
  80. .btn:hover {
  81. border-radius: 5px;
  82. color: #fff;
  83. background: #03e9f4;
  84. box-shadow: 0 0 5px 0 #03e9f4,
  85. 0 0 25px 0 #03e9f4,
  86. 0 0 50px 0 #03e9f4,
  87. 0 0 100px 0 #03e9f4;
  88. transition: all 1s linear;
  89. }
  90. .btn>span {
  91. position: absolute;
  92. }
  93. .btn>span:nth-child(1) {
  94. width: 100%;
  95. height: 2px;
  96. background: -webkit-linear-gradient(left, transparent, #03e9f4);
  97. left: -100%;
  98. top: 0px;
  99. animation: line1 1s linear infinite;
  100. }
  101. @keyframes line1 {
  102. 50%,
  103. 100% {
  104. left: 100%;
  105. }
  106. }
  107. .btn>span:nth-child(2) {
  108. width: 2px;
  109. height: 100%;
  110. background: -webkit-linear-gradient(top, transparent, #03e9f4);
  111. right: 0px;
  112. top: -100%;
  113. animation: line2 1s 0.25s linear infinite;
  114. }
  115. @keyframes line2 {
  116. 50%,
  117. 100% {
  118. top: 100%;
  119. }
  120. }
  121. .btn>span:nth-child(3) {
  122. width: 100%;
  123. height: 2px;
  124. background: -webkit-linear-gradient(left, #03e9f4, transparent);
  125. left: 100%;
  126. bottom: 0px;
  127. animation: line3 1s 0.75s linear infinite;
  128. }
  129. @keyframes line3 {
  130. 50%,
  131. 100% {
  132. left: -100%;
  133. }
  134. }
  135. .btn>span:nth-child(4) {
  136. width: 2px;
  137. height: 100%;
  138. background: -webkit-linear-gradient(top, transparent, #03e9f4);
  139. left: 0px;
  140. top: 100%;
  141. animation: line4 1s 1s linear infinite;
  142. }
  143. @keyframes line4 {
  144. 50%,
  145. 100% {
  146. top: -100%;
  147. }
  148. }
  149. </style>
  150. </head>
  151. <body>
  152. <div class="loginBox">
  153. <h2>login</h2>
  154. <form action="/login" method="post">
  155. <div class="item">
  156. <input type="text" required name="username">
  157. <label >用户名</label>
  158. </div>
  159. <div class="item">
  160. <input type="password" required name="password">
  161. <label >密码</label>
  162. </div>
  163. <button class="btn">登录
  164. <span></span>
  165. <span></span>
  166. <span></span>
  167. <span></span>
  168. </button>
  169. </form>
  170. </div>
  171. </body>
  172. </html>

index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <p align="right">欢迎 {{username}} 登录本系统,密码为{{password}}</p>
  10. <!--使表格居中,长度自适应为60%-->
  11. <table border = 1 style="margin: auto;" width="60%">
  12. {% for item in my_list %}
  13. <tr>
  14. <!--列是id,行是value-->
  15. <th> {{ item.id }} </th>
  16. <td> {{ item.value }}</td>
  17. </tr>
  18. {% endfor %}
  19. </table>
  20. <ul>
  21. {% for item in my_list %}
  22. <!--# loop是jinjia2里的内置循环变量,loop.index是从1开始升序(循环迭代)-->
  23. {% if loop.index == 1 %}
  24. <li style="background-color: red;">{{loop.index}}----{{item.get('value')}}</li>
  25. {% elif loop.index == 2 %}
  26. <li style="background-color: gray;">{{loop.index}}----{{item.get('value')}}</li>
  27. {% elif loop.index == 3 %}
  28. <li style="background-color: blue;">{{loop.index}}----{{item.get('value')}}</li>
  29. {% else %}
  30. <li style="background-color: yellow;">{{loop.index}}----{{item.get('value')}}</li>
  31. {% endif %}
  32. {% endfor %}
  33. </ul>
  34. </body>
  35. </html>

三、简单的注册登录页面

逻辑:

main.py:

因为有三个html页面,所以必须有三个路由,这里我设置了如下三个路由:

  • /路由
    • 根路由下绑定了有关登录成功html的函数
  • /login路由
    • login路由下的绑定了有关验证登录的函数:
      • ①使用request.form.get()方法拿到用户输入的用户名和密码,(在login.html页面和register.html页面中用户输入的用户名和密码都是在input标签中写的,使用name属性唯一确定它们的值,在request.form.get()里输入name值,就可以拿到)
      • ②创建表
      • ③连接数据库,如果用户输入的用户名和密码在数据库中,则登录成功,跳转到登录成功后的界面;如果用户输入的用户名和密码不在数据库中跳转到login界面
  • /register路由
    • /register路由下的绑定了有关验证登录的函数:
      • ①连接数据库
      • ②创建表
      • ③连接数据库,使用request.form.get()方法拿到用户输入的用户名和密码,如果不在数据库中则注册成功;(但是我没有实现判断用户输入的用户名和密码是否在数据库中,这里要靠JS实现用户唯一)

main2.py

  1. from turtle import title
  2. import requests
  3. from flask import Flask, render_template, request, redirect, url_for, flash, session
  4. import pymysql
  5. app = Flask(__name__)
  6. # 添加会话一定要设置密钥
  7. app.secret_key = 'asdffbgsc'
  8. @app.route('/')
  9. def index():
  10. list1 = list(range(10))
  11. my_list = [
  12. {'id': 1, 'value': '我爱工作'},
  13. {'id': 2, 'value': '工作使人快乐'},
  14. {'id': 3, 'value': '沉迷工作无法自拔'},
  15. {'id': 4, 'value': '日渐消瘦'},
  16. {'id': 5, 'value': '以梦为马,不负韶华'}, ]
  17. # 将title,list2,render_template这三个变量的内容渲染到index.html页面中
  18. return render_template('index.html', title='hello world', list2=list1, my_list=my_list,
  19. username=session.get('username'), password=session.get('password'))
  20. # 自定义过滤器
  21. def do_listreverse(aa):
  22. temp_li = list(aa)
  23. temp_li.reverse() # 将列表反转
  24. return temp_li
  25. # 验证登录
  26. @app.route('/login', methods=['GET', 'POST'])
  27. def login():
  28. if request.method == 'POST':
  29. connect_db = pymysql.connect(host='192.168.198.142',
  30. port=3306,
  31. user='root',
  32. password='Nebula@123',
  33. database='Python_Test')
  34. connect_course = connect_db.cursor()
  35. select_query = 'select * from user_info'
  36. connect_course.execute(select_query)
  37. user_info = connect_course.fetchall()
  38. username = request.form.get('username')
  39. password = request.form.get('password')
  40. for row in user_info:
  41. user_name.append(row[1])
  42. user_password.append(row[2])
  43. if username in user_name and password in user_password:
  44. print("登录成功!")
  45. # 设置会话,拿到全局的内容
  46. session['username'] = username
  47. session['password'] = password
  48. return redirect('/')
  49. else:
  50. flash("用户名或密码错误")
  51. return render_template('login.html')
  52. # 注册
  53. user_id = []
  54. user_name = []
  55. user_password = []
  56. @app.route('/register', methods=['GET', 'POST'])
  57. def register():
  58. if request.method == 'POST': # 要和methods里面的POST一致
  59. # 创建链接
  60. connect_db = pymysql.connect(host='192.168.198.142',
  61. port=3306,
  62. user='root',
  63. password='Nebula@123',
  64. database='Python_Test')
  65. connect_course = connect_db.cursor()
  66. # 创建表
  67. create_table_sql = "create table if not exists user_info(id int NOT NULL auto_increment primary key," \
  68. "user_name varchar(30)," \
  69. "user_pass varchar(20))"
  70. connect_course.execute(create_table_sql)
  71. select_query = 'select * from user_info'
  72. connect_course.executemany(select_query)
  73. rows = connect_course.fetchall()
  74. # print(rows)
  75. for row in rows:
  76. user_id.append(row[0])
  77. user_name.append(row[1])
  78. user_password.append(row[2])
  79. user_list = list(map(list, zip(user_id, user_name, user_password)))
  80. for user in user_list:
  81. username = request.form.get('username')
  82. password = request.form.get('password')
  83. # print(username,password)
  84. # 如果用户不存在,插入信息
  85. if username != user[1]:
  86. try:
  87. insert_query = 'insert into user_info values(NULL,%s,%s);'
  88. user_datas = [(username, password)]
  89. # 它是一个列表所以使用executemany
  90. connect_course.executemany(insert_query, user_datas)
  91. connect_db.commit()
  92. print('插入成功!')
  93. # print(rows)
  94. except Exception as e:
  95. print(e, '插入失败!')
  96. connect_db.close()
  97. return render_template('login.html')
  98. else:
  99. flash('用户名已存在请重新输入')
  100. return render_template('register.html')
  101. # 注册过滤器
  102. # 第一个参数是函数名,第二个是过滤器的名字,可在所有模板上使用这个函数
  103. app.add_template_filter(do_listreverse, 'listreverse')
  104. if __name__ == '__main__':
  105. app.run(debug=True)

登录页面:login.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>登录</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. a {
  13. text-decoration: none;
  14. }
  15. input,
  16. button {
  17. background: transparent;
  18. border: 0;
  19. outline: none;
  20. }
  21. body {
  22. height: 100vh;
  23. background: linear-gradient(#141e30, #243b55);
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. font-size: 16px;
  28. color: #03e9f4;
  29. }
  30. .loginBox {
  31. width: 400px;
  32. height: 364px;
  33. background-color: #0c1622;
  34. margin: 100px auto;
  35. border-radius: 10px;
  36. box-shadow: 0 15px 25px 0 rgba(0, 0, 0, .6);
  37. padding: 40px;
  38. box-sizing: border-box;
  39. }
  40. h2 {
  41. text-align: center;
  42. color: aliceblue;
  43. margin-bottom: 30px;
  44. font-family: 'Courier New', Courier, monospace;
  45. }
  46. .item {
  47. height: 45px;
  48. border-bottom: 1px solid #fff;
  49. margin-bottom: 40px;
  50. position: relative;
  51. }
  52. .item input {
  53. width: 100%;
  54. height: 100%;
  55. color: #fff;
  56. padding-top: 20px;
  57. box-sizing: border-box;
  58. }
  59. .item input:focus+label,
  60. .item input:valid+label {
  61. top: 0px;
  62. font-size: 2px;
  63. }
  64. .item label {
  65. position: absolute;
  66. left: 0;
  67. top: 12px;
  68. transition: all 0.5s linear;
  69. }
  70. .btn {
  71. padding: 10px 20px;
  72. margin-top: 30px;
  73. color: #03e9f4;
  74. position: relative;
  75. overflow: hidden;
  76. text-transform: uppercase;
  77. letter-spacing: 2px;
  78. left: 35%;
  79. }
  80. .btn:hover {
  81. border-radius: 5px;
  82. color: #fff;
  83. background: #03e9f4;
  84. box-shadow: 0 0 5px 0 #03e9f4,
  85. 0 0 25px 0 #03e9f4,
  86. 0 0 50px 0 #03e9f4,
  87. 0 0 100px 0 #03e9f4;
  88. transition: all 1s linear;
  89. }
  90. .btn>span {
  91. position: absolute;
  92. }
  93. .btn>span:nth-child(1) {
  94. width: 100%;
  95. height: 2px;
  96. background: -webkit-linear-gradient(left, transparent, #03e9f4);
  97. left: -100%;
  98. top: 0px;
  99. animation: line1 1s linear infinite;
  100. }
  101. @keyframes line1 {
  102. 50%,
  103. 100% {
  104. left: 100%;
  105. }
  106. }
  107. .btn>span:nth-child(2) {
  108. width: 2px;
  109. height: 100%;
  110. background: -webkit-linear-gradient(top, transparent, #03e9f4);
  111. right: 0px;
  112. top: -100%;
  113. animation: line2 1s 0.25s linear infinite;
  114. }
  115. @keyframes line2 {
  116. 50%,
  117. 100% {
  118. top: 100%;
  119. }
  120. }
  121. .btn>span:nth-child(3) {
  122. width: 100%;
  123. height: 2px;
  124. background: -webkit-linear-gradient(left, #03e9f4, transparent);
  125. left: 100%;
  126. bottom: 0px;
  127. animation: line3 1s 0.75s linear infinite;
  128. }
  129. @keyframes line3 {
  130. 50%,
  131. 100% {
  132. left: -100%;
  133. }
  134. }
  135. .btn>span:nth-child(4) {
  136. width: 2px;
  137. height: 100%;
  138. background: -webkit-linear-gradient(top, transparent, #03e9f4);
  139. left: 0px;
  140. top: 100%;
  141. animation: line4 1s 1s linear infinite;
  142. }
  143. @keyframes line4 {
  144. 50%,
  145. 100% {
  146. top: -100%;
  147. }
  148. }
  149. </style>
  150. </head>
  151. <body>
  152. <div class="loginBox">
  153. <h2>login</h2>
  154. <form action="/login" method="post">
  155. <div class="item">
  156. <input type="text" required name="username">
  157. <label >用户名</label>
  158. </div>
  159. <div class="item">
  160. <input type="password" required name="password">
  161. <label >密码</label>
  162. <!--使标签居右-->
  163. <div class="son">
  164. <!-- href通过路由跳转到register界面-->
  165. <a style="display: block;text-align:right;" href="/register" target="_blank">没有账号?去注册</a>
  166. </div>
  167. </div>
  168. <button class="btn">登录
  169. <span></span>
  170. <span></span>
  171. <span></span>
  172. <span></span>
  173. </button>
  174. </form>
  175. </div>
  176. </body>
  177. </html>


登录成功的页面:index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <!--接收从main.py传递的参数-->
  11. <!--通过listreverse过滤器将传递过来的参数反转并且转成大写-->
  12. <!-- <h1>{{title | listreverse | upper}}</h1>-->
  13. <!-- <br>-->
  14. <!--&lt;!&ndash;无序列表,ol是有序列表&ndash;&gt;-->
  15. <!-- <ul>-->
  16. <!--&lt;!&ndash;# 使用for循环遍历传过来的参数&ndash;&gt;-->
  17. <!-- {% for item in my_list %}-->
  18. <!--&lt;!&ndash;# 使用列表标签将内容一行一行显示,在main.py里mylist是一个大列表嵌套很多小的字典,其中id是k值,value是v值&ndash;&gt;-->
  19. <!-- <li>{{item.id}}&#45;&#45;&#45;&#45;{{item.value}}</li>-->
  20. <!-- {% endfor %}-->
  21. <!-- </ul>-->
  22. <p align="right">欢迎 {{username}} 登录本系统,密码为{{password}}</p>
  23. <!--使表格居中,长度自适应为60%-->
  24. <table border = 1 style="margin: auto;" width="60%">
  25. {% for item in my_list %}
  26. <tr>
  27. <!--列是id,行是value-->
  28. <th> {{ item.id }} </th>
  29. <td> {{ item.value }}</td>
  30. </tr>
  31. {% endfor %}
  32. </table>
  33. <ul>
  34. {% for item in my_list %}
  35. <!--# loop是jinjia2里的内置循环变量,loop.index是从1开始升序(循环迭代)-->
  36. {% if loop.index == 1 %}
  37. <li style="background-color: red;">{{loop.index}}----{{item.get('value')}}</li>
  38. {% elif loop.index == 2 %}
  39. <li style="background-color: gray;">{{loop.index}}----{{item.get('value')}}</li>
  40. {% elif loop.index == 3 %}
  41. <li style="background-color: blue;">{{loop.index}}----{{item.get('value')}}</li>
  42. {% else %}
  43. <li style="background-color: yellow;">{{loop.index}}----{{item.get('value')}}</li>
  44. {% endif %}
  45. {% endfor %}
  46. </ul>
  47. </body>
  48. </html>


注册页面:register.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>注册</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. a {
  13. text-decoration: none;
  14. }
  15. input,
  16. button {
  17. background: transparent;
  18. border: 0;
  19. outline: none;
  20. }
  21. body {
  22. height: 100vh;
  23. background: linear-gradient(#141e30, #243b55);
  24. display: flex;
  25. justify-content: center;
  26. align-items: center;
  27. font-size: 16px;
  28. color: #03e9f4;
  29. }
  30. .loginBox {
  31. width: 400px;
  32. height: 364px;
  33. background-color: #0c1622;
  34. margin: 100px auto;
  35. border-radius: 10px;
  36. box-shadow: 0 15px 25px 0 rgba(0, 0, 0, .6);
  37. padding: 40px;
  38. box-sizing: border-box;
  39. }
  40. h2 {
  41. text-align: center;
  42. color: aliceblue;
  43. margin-bottom: 30px;
  44. font-family: 'Courier New', Courier, monospace;
  45. }
  46. .item {
  47. height: 45px;
  48. border-bottom: 1px solid #fff;
  49. margin-bottom: 40px;
  50. position: relative;
  51. }
  52. .item input {
  53. width: 100%;
  54. height: 100%;
  55. color: #fff;
  56. padding-top: 20px;
  57. box-sizing: border-box;
  58. }
  59. .item input:focus+label,
  60. .item input:valid+label {
  61. top: 0px;
  62. font-size: 2px;
  63. }
  64. .item label {
  65. position: absolute;
  66. left: 0;
  67. top: 12px;
  68. transition: all 0.5s linear;
  69. }
  70. .btn {
  71. padding: 10px 20px;
  72. margin-top: 30px;
  73. color: #03e9f4;
  74. position: relative;
  75. overflow: hidden;
  76. text-transform: uppercase;
  77. letter-spacing: 2px;
  78. left: 35%;
  79. }
  80. .btn:hover {
  81. border-radius: 5px;
  82. color: #fff;
  83. background: #03e9f4;
  84. box-shadow: 0 0 5px 0 #03e9f4,
  85. 0 0 25px 0 #03e9f4,
  86. 0 0 50px 0 #03e9f4,
  87. 0 0 100px 0 #03e9f4;
  88. transition: all 1s linear;
  89. }
  90. .btn>span {
  91. position: absolute;
  92. }
  93. .btn>span:nth-child(1) {
  94. width: 100%;
  95. height: 2px;
  96. background: -webkit-linear-gradient(left, transparent, #03e9f4);
  97. left: -100%;
  98. top: 0px;
  99. animation: line1 1s linear infinite;
  100. }
  101. @keyframes line1 {
  102. 50%,
  103. 100% {
  104. left: 100%;
  105. }
  106. }
  107. .btn>span:nth-child(2) {
  108. width: 2px;
  109. height: 100%;
  110. background: -webkit-linear-gradient(top, transparent, #03e9f4);
  111. right: 0px;
  112. top: -100%;
  113. animation: line2 1s 0.25s linear infinite;
  114. }
  115. @keyframes line2 {
  116. 50%,
  117. 100% {
  118. top: 100%;
  119. }
  120. }
  121. .btn>span:nth-child(3) {
  122. width: 100%;
  123. height: 2px;
  124. background: -webkit-linear-gradient(left, #03e9f4, transparent);
  125. left: 100%;
  126. bottom: 0px;
  127. animation: line3 1s 0.75s linear infinite;
  128. }
  129. @keyframes line3 {
  130. 50%,
  131. 100% {
  132. left: -100%;
  133. }
  134. }
  135. .btn>span:nth-child(4) {
  136. width: 2px;
  137. height: 100%;
  138. background: -webkit-linear-gradient(top, transparent, #03e9f4);
  139. left: 0px;
  140. top: 100%;
  141. animation: line4 1s 1s linear infinite;
  142. }
  143. @keyframes line4 {
  144. 50%,
  145. 100% {
  146. top: -100%;
  147. }
  148. }
  149. </style>
  150. </head>
  151. <body>
  152. <div class="loginBox">
  153. <h2>register</h2>
  154. <form action="/register" method="post">
  155. <div class="item">
  156. <input type="text" required name="username">
  157. <label >用户名</label>
  158. </div>
  159. <div class="item">
  160. <input type="password" required name="password">
  161. <label >密码</label>
  162. </div>
  163. <button class="btn">注册
  164. <span></span>
  165. <span></span>
  166. <span></span>
  167. <span></span>
  168. </button>
  169. </form>
  170. </div>
  171. </body>
  172. </html>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/747701
推荐阅读
相关标签
  

闽ICP备14008679号