1.ajax
from flask import Flask, request
app = Flask(__name__)
from flask_cors import CORS
CORS(app, supports_credentials=True)
@app.route('/')
def home_action():
return '<h1 style="color: red">主页</h1>'
@app.route('/login')
def login_action():
user = request.args['user']
pwd = request.args['pwd']
if user == 'abc' and pwd == '123':
return "登录成功"
return "登录失败"
if __name__ == '__main__':
app.run(port="8888")
<h1>请登录</h1>
<form class="fm">
<input id="user" type="text" name="user" placeholder="请输入用户名">
<input id="pwd" type="password" name="pwd" placeholder="请输入密码">
<input class="sbm" type="submit" value="提交...">
</form>
$('.fm').submit(function () { return false; })
$('.sbm').click(function () {
var user = $('#user').val();
var pwd = $('#pwd').val();
$.ajax({
url: "http://127.0.0.1:8888/login",
data: {
user: user,
pwd: pwd
},
success: function (data) {
doSomething(data);
}
})
});
function doSomething(data) {
$('h1').text(data)
}
2.bootstrap
<head>
<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
<link rel="stylesheet" href="css/my.css">
</head>
<body>
...
<script src="js/jquery-3.3.1.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>
</body>
<div class="container">
<div class="row">
<h1 class="bg-info">标题</h1>
</div>
</div>
<div class="container-fluid">
<div class="row">
<h1 class="bg-info">标题</h1>
</div>
</div>