1:原始视图:
from app import app
@app.route('/user/index') def index(): return 'user_index'
@app.route('/user/show') def show(): return 'user_show'
@app.route('/user/add') def add(): return 'user_add'
@app.route('/admin/index') def adminindex(): return 'admin_index'
@app.route('/admin/show') def adminshow(): return 'admin_show'
@app.route('/admin/add') def adminadd(): return 'admin_add'
2、使用蓝图使之pythonic
from flask import Blueprint,render_template, request
admin = Blueprint('admin', name)
@admin.route('/index') def index(): return render_template('admin/index.html')
@admin.route('/add') def add(): return 'admin_add'
@admin.route('/show') def show(): return 'admin_show'
from flask import Blueprint, render_template, redirect
user = Blueprint('user',name)
@user.route('/index') def index(): return render_template('user/index.html')
@user.route('/add') def add(): return 'user_add'
@user.route('/show') def show(): return 'user_show'
from app import app from .user import user from .admin import admin
app.register_blueprint(admin,url_prefix='/admin') app.register_blueprint(user, url_prefix='/user')
admin=Blueprint('admin',name) @admin.route('/xx')
from .admin import admin app.register_blueprint(admin,url_prefix='/admin')