flask和bootstrp

1.目录结构:

root@bogon:~# tree flask/yw/
flask/yw/
├── bootstrap.zip #下载的bootstrap,解压的文件移动到下面的static目录里
├── run.py #运行配置文件
├── static #静态文件目录,存放静态文件,如:css...等,把bootstrap解压的文件移动到这个目录下
│   ├── css
│   │   ├── bootstrap.css
│   │   ├── bootstrap.min.css
│   │   ├── bootstrap-responsive.css
│   │   └── bootstrap-responsive.min.css
│   ├── fonts
│   │   ├── glyphicons-halflings-regular.eot
│   │   ├── glyphicons-halflings-regular.svg
│   │   ├── glyphicons-halflings-regular.ttf
│   │   └── glyphicons-halflings-regular.woff
│   ├── img  #图片目录
│   │   ├── 2014
│   │   │   ├── bing.png      #画的饼状图片
│   │   │   └── ttt.png       #画的流量图
│   │   ├── glyphicons-halflings.png
│   │   └── glyphicons-halflings-white.png
│   ├── index.html
│   ├── index.html.bak
│   └── js
│       ├── bootstrap.js
│       ├── bootstrap.min.js
│       └── npm.js
├── static.tar.gz
└── templates    #模板文件
    ├── admin.html
    ├── admin_info.html
    ├── base.html
    ├── cmd.html
    ├── docker.html
    ├── fw.html
    ├── kvm.html
    ├── ll.html
    ├── login.html
    ├── mode_base_index.html
    └── salt.html

2.运行配置文件内容:

root@bogon:~# cat flask/yw/run.py 
#!/bin/python 
from flask import Flask,flash,request,render_template,url_for,redirect,session,abort,escape
import os,sqlite3,datetime
SECRET_KEY = '123456'
app = Flask(__name__)
app.config.from_envvar('FLASKR_SETTING',silent=True)
app.secret_key = '123456'

##########################################################


##########################################################
@app.route('/',methods=['GET','POST'])
def index():
    if 'username' not in session or session['username'] == '':
        return redirect(url_for('login'))
    else:
        return redirect(url_for('admin2'))


@app.route('/login/',methods=['GET','POST'])
def login():
    if request.method == 'POST':
        session['username'] = request.form['username']
        session['passwd']   = request.form['passwd']
        username = request.form['username']
        passwd = request.form['passwd']
        if username == None  or passwd == '':
            return redirect(url_for('login'))
        #return redirect(url_for('user'))
        else:
            return redirect(url_for('admin2'))
    return render_template('login.html')


@app.route('/admin2/',methods=['GET','POST'])
@app.route('/admin2/<post_info>',methods=['GET','POST'])
def admin2(post_info='info',state=None,ser=None):
    shell=[]
    info=[]
    info.append(os.popen('df -m').read())
    info.append(os.popen('free -m').read())
    info.append(os.popen('uname -a').read())
    info.append(os.popen('uptime').read())
    info.append(os.popen('ifconfig eth0|grep inet').read())
    if 'username' not in session or session['username'] == '':
        return redirect(url_for('login'))
    else:
        username = session['username']
    if post_info == 'info':
        active='active'
        return render_template('admin_info.html',info=info,username=username,active_info=active)
    if post_info == 'll':
        active='active'
        return render_template('ll.html',username=username,active_ll=active)
    if post_info == 'fw':
        active='active'
        if request.method == 'POST':
            aa= request.form
            fw_active='/etc/init.d/'
            if 'start' in aa:os.system("%s%s  start"%(fw_active,aa['start']))
            if 'stop' in aa:os.system('%s%s stop'%(fw_active,aa['stop']))
            if 'restart' in aa:os.system('%s%s  restart'%(fw_active,aa['restart']))
        fw=os.popen('service --status-all').read().split('\n')
        fw.remove('')
        return render_template('fw.html',fw=fw,username=username,active_fw=active)
    if post_info == 'cmd':
        active='active'
        if request.method == 'POST':
            print request.form
            cmd = request.form['cmd-txt']
            shell= os.popen(cmd).read()
        return render_template('cmd.html',shell=shell,username=username,active_cmd=active)
    if post_info == 'kvm':
        active='active'
        return render_template('kvm.html',username=username,active_kvm=active)
    if post_info == 'docker':
        active='active'
        return render_template('docker.html',username=username,active_docker=active)
    if post_info == 'salt':
        active='active'
        return render_template('salt.html',username=username,active_salt=active)
    if post_info == 'users':
        active='active'
        return render_template('salt.html',username=username,active_users=active)
    if post_info == 'about':
        active='active'
        return render_template('salt.html',username=username,active_about=active)


@app.route('/logout/')
def logout():
    session.pop('username',None)
    session.pop('passwd',None)
    return redirect(url_for('login'))


@app.route('/post/<int:post_id>')
def show_post(post_id):
    return 'post_id:%s' % post_id


if __name__ == '__main__':
    app.run(host='0.0.0.0',port=80,debug=True)

3.bootstrap改造:

http://v3.bootcss.com/examples/signin/

http://v3.bootcss.com/examples/offcanvas/

4.运行效果:

flask和bootstrp_第1张图片

flask和bootstrp_第2张图片

flask和bootstrp_第3张图片

flask和bootstrp_第4张图片

flask和bootstrp_第5张图片

flask和bootstrp_第6张图片


你可能感兴趣的:(bootstrap,flask,bootstrip)