將通用配置應用於WebTeam的所有燒瓶應用程序的燒瓶擴展。
from canonicalwebteam . flask_base . app import FlaskBase
app = FlaskBase ( __name__ , "app.name" )或者:
from canonicalwebteam . flask_base . app import FlaskBase
app = FlaskBase (
__name__ ,
"app.name" ,
template_404 = "404.html" ,
template_500 = "500.html" ,
favicon_url = "/static/favicon.ico" ,
)對於本地開發,最好使用Ubuntu.com等網站項目之一測試該模塊。有關更多信息,請遵循本指南(僅內部)。
玻璃庫包括避免SSL剝離重定向的froxyfix。
FlaskBase使用YAML-RESOPONS,通過創建redirects.yaml , permanent-redirects.yaml和deleted.yaml 。
FlaskBase可以選擇使用模板生成404和500錯誤響應:
app = FlaskBase (
__name__ ,
"app.name" ,
template_404 = "404.html" ,
template_500 = "500.html" ,
)這將導致EG http://localhost/non-existent-path返回404狀態,具有templates/404.html的內容。
FlaskBase可以選擇地為常見的路徑/favicon.ico , /robots.txt和/humans.txt提供重定向到明智的位置:
from canonicalwebteam . flask_base . app import FlaskBase
app = FlaskBase (
__name__ ,
"app.name" ,
template_404 = "404.html" ,
template_500 = "500.html" ,
favicon_url = "/static/favicon.ico" ,
robots_url = "/static/robots.txt" ,
humans_url = "/static/humans.txt"
)這將導致例如http://localhost/favicon.ico返回302重定向到http://localhost/static/favicon.ico 。
自動從所有路線上清除所有落後斜線。
您可以從燒瓶底座中獲得兩個Jinja2幫助者,可以在模板中使用:
now是以傳遞格式輸出當前日期的函數 - {{ now('%Y') }} - > YYYYversioned_static是一個指紋的函數 - {{ versioned_static('asset.js') }} - > static/asset?v=asset-hash您會自動設置以下標題:
X-Content-Type-Options: NOSNIFFPermissions-Policy: interest-cohort=()X-Frame-Options: SAMEORIGIN ,可以用exclude_xframe_options_header Decorator排除Cache-Control versioned_static response.cache_control.*security.txt , robots.txt和humans.txt如果您在項目的根部創建security.txt , robots.txt或humans.txt ,則將分別在/.well-known/security.txt , /robots.txt和/humans.txt上提供這些security.txt。
/_status/check端點自動添加/_status/check ENDPOINT,該端點被內容計算機用於後端健康檢查或K8S用於檢查POD的狀態。
要運行SECRET_KEY=fake python3 -m unittest discover tests Tests 。