def inline_static_file(path, minify=None):
"""
Outputs the [minified] contents of a given static file.
For example, to display the minified CSS file "``inline.css``"::
<style>
{% inline_static_file 'inline.css' 'css' %}
</style>
The optional ``minify`` argument can be one of css, js, or html.
"""
p = finders.find(path)
if not p:
raise RuntimeError('path=%s not found' % path)
elif os.path.isdir(p):
raise RuntimeError('path=%s is not a file' % path)
with open(p, encoding='utf-8') as f:
if minify == 'js':
return mark_safe(js_minify(f.read()))
elif minify == 'css':
return mark_safe(css_minify(f.read()))
elif minify == 'html':
return mark_safe(html_minify(f.read()))
else:
return mark_safe(f.read())
评论列表
文章目录