bootstrap flask登录页面编写实例

作者:lijiao 时间:2024-04-16 08:49:19 

本文章来为各位介绍一个python的例子,这个就是bootstrap+flask写登录页面的例子,希望文章能够对各位有所帮助。

Flask是一个使用 Python 编写的轻量级 Web 应用框架。其 WSGI 工具箱采用 Werkzeug ,模板引擎则使用 Jinja2 。在一般应用或个人开发中,可以很容易的写出应用。本篇就结合bootstrap,写一个简单的login界面。

一、效果图

无图无真像,先上效果图:

 bootstrap flask登录页面编写实例

flask-bootstrap

bootstrap flask登录页面编写实例

flask-login

二、目录结构

该代码写时采用动静分离的方法进行编写,目录树如下:

[root@jb51 login]# tree
.
├── run.py
├── static
│   └── css
│       ├── bootstrap.min.css
│       └── style.css
└── templates
    ├── index.html
    └── login.html

三、入口run文件

动态代码只有一个run.py文件,代码如下:


from flask import *
app = Flask(__name__,static_url_path='/static')
@app.route("/login",methods=['POST','GET'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'admin123':
 error= "sorry"
else:
 return redirect(url_for('index'))
return render_template('login.html',error=error)
@app.route("/index")
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(
host="0.0.0.0",
port=80,
debug=True)

实际应用中,根据需要,可以关闭debug模试。

四、静态模块

templates下有两个模块文件分别是login.html和index.html

login.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0" />
<title>Bootstrap响应式登录界面模板</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<div class="box">
<div class="login-box">
<div class="login-title text-center">
<h1><small>登录</small></h1>
</div>
<div class="login-content ">
<div class="form">
<form action="#" method="post">
<div class="form-group">
<div class="col-xs-12 ">
 <div class="input-group">
  <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
  <input type="text" id="username" name="username" class="form-control" placeholder="用户名">
 </div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12 ">
 <div class="input-group">
  <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
  <input type="text" id="password" name="password" class="form-control" placeholder="密码">
 </div>
</div>
</div>
<div class="form-group form-actions">
<div class="col-xs-4 col-xs-offset-4 ">
 <button type="submit" class="btn btn-sm btn-info"><span class="glyphicon glyphicon-off"></span> 登录</button>
</div>
</div>
<div class="form-group">
<div class="col-xs-6 link">
 <p class="text-center remove-margin"><small>忘记密码?</small> <a href="javascript:void(0)" ><small>找回</small></a>
 </p>
</div>
<div class="col-xs-6 link">
 <p class="text-center remove-margin"><small>还没注册?</small> <a href="javascript:void(0)" ><small>注册</small></a>
 </p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div style="text-align:center;"><p>来源:<a href="https://www.aspxhome.com/" target="_blank">运维之路</a></p></div>
</body>
</html>

index.html
index.html 模板中内容如下:

<h1>welcome to www.aspxhome.com/ <h1>

如果大家还想深入学习,可以点击这里进行学习,再为大家附两个精彩的专题:Bootstrap学习教程Bootstrap实战教程

标签:bootstrap,flask,登录
0
投稿

猜你喜欢

  • Perl初学笔记之Hello World

    2022-05-21 10:28:55
  • mysql数据如何通过data文件恢复

    2024-01-17 18:48:18
  • 如何确定Oracle数据库表重复的记录

    2010-07-26 13:23:00
  • PHP使用redis实现分布式锁的示例详解

    2023-06-01 16:32:19
  • MySQL source导入很慢的解决方法

    2024-01-25 18:25:49
  • 如何用Python和JS实现的Web SSH工具

    2021-04-23 13:50:13
  • python函数的作用域及关键字详解

    2021-11-26 04:38:30
  • TensorFlow tf.nn.max_pool实现池化操作方式

    2021-08-20 20:36:45
  • vue实现价格日历效果

    2023-07-02 17:01:14
  • Python根据成绩分析系统浅析

    2023-08-02 20:25:07
  • Python正则表达式常用函数总结

    2023-07-27 12:37:41
  • 你需要学会的8个Python列表技巧

    2023-11-19 09:36:21
  • python Selenium爬取内容并存储至MySQL数据库的实现代码

    2024-01-13 17:51:28
  • JS:firefox 兼容性问题

    2009-08-01 16:20:00
  • PHP的mysqli_thread_id()函数讲解

    2023-06-13 10:09:43
  • 详解 Go 语言中 Map 类型和 Slice 类型的传递

    2024-05-29 22:07:11
  • 详解Django框架中的视图级缓存

    2021-02-02 02:13:33
  • vue项目中全局引入1个.scss文件的问题解决

    2024-05-29 22:44:38
  • opencv-python基本图像处理详解

    2021-07-07 04:37:02
  • Oracle收购TimesTen 提高数据库软件性能

    2010-07-21 13:03:00
  • asp之家 网络编程 m.aspxhome.com