消息提示flash()深入—Flask网站制作(21)
Flask网站制作框架
快速制作网站,提高技术,增加面试砝码!
安装:pip install Flask
消息提示flash()深入
HTML页面:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>简易人事管理系统 V 2.0 登录</title>
<link href="/static/css/bootstrap.css" rel="stylesheet">
<script src="/static/jquery.min.js"></script>
<script src="/static/js/bootstrap.js"></script>
</head>
<body>
<h2 class="well text-center">简易人事管理系统</h2>
<form class="well form-horizontal" method="POST">
<div class="form-group well text-center">
{% if get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<h3 style="color:red"><strong>注意:</strong> {{ get_flashed_messages()[0] }}</h3>
</div>
<br><br>
{% endif %}
<div class="col-md-4"></div>
<label for="name" class="col-md-1 control-label">用户名:</label>
<div class="col-md-3">
{{form.username(class="form-control")}}
{#<input type="text" class="form-control" id="name" placeholder="输入姓名">#}
</div>
<br><br>
<div class="col-md-4"></div>
<label for="bumen" class="col-md-1 control-label">密    码:</label>
<div class="col-md-3">
{{form.password(class="form-control")}}
{#<input type="text" class="form-control" id="bumen" placeholder="输入密码">#}
</div>
<br><br><br><br>
<input type="submit" class="btn btn-primary" value="提交"></button>
            
<button type="reset" class="btn btn-primary">重置</button>
            
<button type="button" class="btn btn-primary">修改密码</button>
</div>
</form>
<div class="well text-center">
简易人事管理系统的版权已受法律保护,未经允许的传播均属于非法传播
</div>
</body>
</html>
{% if get_flashed_messages() %}
<div class="col-md-4"></div>
<div class="text-centercol-md-4 alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<h3 style="color:red"><strong>注意:</strong> {{ get_flashed_messages()[0] }}</h3>
</div>
<div class="col-md-4"></div>
{% endif %}
-
×为设置一个叉,点击这个叉可关闭消息提示框 -
alert-warning代表弹出框底色为粉红色 -
<strong>标签代表加粗
视图文件:
# coding=utf-8
from flask import request,render_template,redirect,url_for,flash
from flask.views import MethodView
from flask import Blueprint
from login.models import loginform
from wtforms import validators
from login.models import *
from home.views import *
login=Blueprint("login",__name__)
class thislogin(MethodView):
def __init__(self):
self.ins_loginform = loginform(request.form)
def get(self):
return render_template("/login.html/",form=self.ins_loginform)
def post(self):
username = self.ins_loginform.username.data
password = self.ins_loginform.password.data
if username == "admin"and password == "123456":
return render_template("/home/home.html")
else:
flash("用户名或密码错误")
return render_template("/login.html/",form=self.ins_loginform)
login.add_url_rule("/",view_func=thislogin.as_view("login"))
呈现效果:
敏感信息,涂抹去公司名称。
模态窗消息提示
<form class="wellform-horizontal" enctype="multipart/form-data" id="interface_updownloads_form"method="POST">
{% if get_flashed_messages() %}
{% if "未选择"in get_flashed_messages()[0] or "只能" inget_flashed_messages()[0] %}
<div class="text-centercol-md-12 alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<h3 style="color:red"><strong>注意:</strong> {{ get_flashed_messages()[0] }} <strong>:(</strong></h3>
</div>
{% else %}
<div class="col-md-4"></div>
<div class="text-center col-md-4 alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<h3 style="color:red">{{ get_flashed_messages()[0] }} <strong>:)</strong></h3>
</div>
<div class="col-md-4"></div>
{% endif %}
{% endif %}
<!-- 模态框(Modal) -->
<div class="modal fade" id="delete_alert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">删除</h4>
</div>
<div class="modal-body">
你将删除该产品下的所有接口,请确认是否需要先行下载这些接口,确认删除?
</div>
<div class="modal-footer">
{{ form.delete_sub(class="btn btn-primary") }} {# 删除接口按钮#}
<button type="button" class="btnbtn-primary" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
<div class="col-md-5">
{{form.search_content(class="form-control",id="search_content")}} {# 选择产品下拉框 #}
</div>
<br><br><br><br>
<div class="col-md-12">
<div class="col-md-1">
{{form.upload_sub(class="btn btn-primary")}} {# 上传按钮 #}
</div>
<div class="col-md-1"></div>
<div class="col-md-10">
{{form.selectfile(class="btnbtn-primary",id="selectfile_sub") }} {# 选择附件按钮#}
</div>
</div>
</div>
<br><br><br><br>
<div class="col-md-2">
<div class="col-md-1">
<a class="btn btn-primary" data-toggle="modal" data-target="#delete_alert" role="button">删除接口</a>
</div>
</div>
<br><br><br><br>
<div class="col-md-2">
<div class="col-md-1">
{{ form.download_sub(class="btn btn-primary")}} {# 下载接口#}
</div>
</div>
<br><br><br><br>
<div class="col-md-2">
<div class="col-md-1">
{{ form.download_emplate_sub(class="btn btn-primary")}} {# 下载模板#}
</div>
</div>
<br><br><br><br>
<div class="col-md-2">
<div class="col-md-1">
<a class="btn btn-primary" href={{url_for("interface.interface_list",scp=scp,which_page=which_page,ud=4,is_intodb=0)}}role="button"><span class="glyphicon glyphicon-share-alt"></span> 返回</a>
</div>
</div>
</form>
无论上课或自学,
你首先需要准备:
每天 2 小时+的学习时间,
每天坚持写代码的习惯!
有投入才有产出,
10k+的涨幅需要 1 年以上的努力!
祝你成功!
光荣之路出品