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':'参数不能为空'})
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')
|