flask之蓝图

http://www.cnblogs.com/wupeiqi/articles/7552008.html  

 

这些都是我们手动创建的

templates

login.html

<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
</head>
<body>
    <h1>用户登录</h1>
</body>
</html>

views

account.py

from flask import Blueprint,render_template
import redis

ac = Blueprint('ac',__name__)

@ac.route('/login')
def login():
    conn = redis.Redis()
    return render_template('login.html')


@ac.route('/logout')
def logout():
    return '大人'

admin.py

from flask import Blueprint

ad = Blueprint('ad',__name__,url_prefix='/admin')

@ad.before_request
def bf():
    print('before_request')


@ad.route('/home')
def home():
    return 'home'

@ad.route('/xxxx')
def xxxx():
    return 'xxxx'

user.py

from flask import Blueprint


us = Blueprint('us',__name__)

@us.route('/info')
def info():
    return 'info'

__init__.py

from flask import Flask
from .views import account
from .views import admin
from .views import user


app = Flask(__name__)


app.register_blueprint(account.ac)
app.register_blueprint(admin.ad)
app.register_blueprint(user.us)

manage.py

from s8pro import app

if __name__ == '__main__':
    app.run()

requirements.txt

redis==2.10.6
Flask==0.12.2

 

posted @ 2018-05-01 11:29  兰博~~  阅读(147)  评论(0编辑  收藏  举报