1. 程式人生 > >flask+blueprint路由配置

flask+blueprint路由配置

int html 如果 filename 構造 pri blueprint 路由 參數

1、flask默認的靜態文件和html文件在app應用文件夾裏的相應文件夾下:
app // Flask
|
|--static
|
|--templates
|
靜態文件默認的url地址為:url_prefix of app + /static 如:/chat/static/xxx.ico
靜態文件默認存放文件夾為: static文件夾

如果想改變默認的static文件夾或/和靜態文件url前綴,在構造Flask對象時修改兩個參數中一個或兩個即可
app = Flask(__name__, static_folder=‘‘, static_url_path=‘‘)

訪問的時候用:
url_for(‘static‘, filename=‘設置的文件夾名/文件名‘)

2、對於blueprint,也有相同功能的參數
admin // Blueprint
|
|--static
|
|--templates
|

靜態文件默認的url地址為:url_prefix of the blueprint + /static,如:admin/static
靜態文件默認存放文件夾為: static文件夾

如果想改變默認的static文件夾或/和靜態文件url前綴,在構造Flask對象時修改兩個參數中一個或兩個即可
admin = Blueprint(‘admin‘, __name__, static_folder=‘‘, static_url_path=‘‘)

訪問的時候用:
url_for(‘admin.static‘, filename=‘style.css‘)

flask+blueprint路由配置