flask

Python Flask Web 框架入门 - 执着的怪味豆 - 博客园 (cnblogs.com)https://www.cnblogs.com/cleven/p/10858016.html

from flask import Flask, render_template, request, url_for, flash, redirect
import json

app = Flask(__name__)
app.config['SECRET_KEY'] = 'DIDAIDAD,555'


@app.route('/hosts/restore/')
def restore():
    get_data = request.args.to_dict()
    host = get_data.get('host')
    database = get_data.get('database')
    data = {'host':host,'base':database}
    if host not in ['123','456']:
        return jsonify({'msg':'ip not exit'})
    else:
        return jsonify(data)

@app.route('/hosts/back/', methods=['post'])
def back():
    if request.method=='POST':
        #host = request.get_data()
        #database = request.get_data('database')
        #data = {'host': host, 'base': database}
        host = request.form.get('host')
        database = request.form.get('database')
        if not host or not database:
            return jsonify({'msg':'参数不能为空'})


docker 使用CMD或者ENTRYPOINT命令同时启动多个服务_docker_脚本之家 (jb51.net)
        else:
            data = {'host':host,'base':database}
            return data
@app.route("/")
def index():
    #return "主页"
    lt = ['aaa', 'bbb', 'ccc']
    return render_template("index.html", datas = lt)
#set FLASK_APP=web   (export FLASK_APP=web)
#set FLASK_ENV=development  (export FLASK_ENV=development)
#flask run
@app.route("/hosts/<int:data_id>")
def hosts(data_id):
    return render_template("host.html")

@app.route('/hosts/backup', methods=('GET', 'POST'))
def backup():
    if request.method == 'POST':
        title = request.form['title']
        con = request.form['con']

        if not title:
            flash('标题不能为空')
        elif not con:
            flash('内容不能为空')
        else:
            #conn = get_db_conn()
            #conn.execute('insert into posts (title, content) values (?,?)',(title,con))
            #conn.commit()
            #conn.close()
            flash('保存成功')
            return redirect(url_for('index'))
    return render_template('host.html')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值