Flask 开发技巧,填坑记录,不定期更新

模板添加全局函数

app.add_template_global(lambda: True, "foo")

使用本地

app.config['BOOTSTRAP_SERVE_LOCAL'] = True

flask-bootstrap 替换CDN

from flask_bootstrap import Bootstrap, \
    WebCDN, ConditionalCDN, \
    BOOTSTRAP_VERSION, JQUERY_VERSION, HTML5SHIV_VERSION, RESPONDJS_VERSION

# 修改国内CDN
cdns = app.extensions['bootstrap']['cdns']
cdns['jquery'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['local'], WebCDN('//cdn.bootcss.com/jquery/%s/' % JQUERY_VERSION))
cdns['bootstrap'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['local'], WebCDN('//cdn.bootcss.com/bootstrap/%s/' % BOOTSTRAP_VERSION))
cdns['html5shiv'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['static'], WebCDN('//cdn.bootcss.com/html5shiv/%s/' % HTML5SHIV_VERSION))
cdns['respond'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['static'], WebCDN('//cdn.bootcss.com/respond/%s/' % RESPONDJS_VERSION))


flask-bootstrap4 替换CDN

from flask_bootstrap import Bootstrap, \
    WebCDN, ConditionalCDN, \
    BOOTSTRAP_VERSION, JQUERY_VERSION, POPPER_VERSION

# 修改CDN国内或使用本地
cdns = app.extensions['bootstrap']['cdns']
cdns['jquery'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['local'],
                                WebCDN('//cdn.bootcss.com/jquery/%s/' % JQUERY_VERSION))
cdns['popper.js'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['local'],
                                   WebCDN('//cdn.bootcss.com/popper.js/%s/' % POPPER_VERSION))
cdns['bootstrap'] = ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', cdns['local'],
                                   WebCDN('//cdn.bootcss.com/bootstrap/%s/' % BOOTSTRAP_VERSION))

转载于:https://my.oschina.net/flywuya/blog/1791337

你可能感兴趣的:(Flask 开发技巧,填坑记录,不定期更新)