def static_url(context, static_file_path):
"""
jinja2 filter for generating urls for static files. NOTE: heed the warning in create_app about "static_root_url"
as this filter uses app['static_root_url'].
Usage:
{%- raw %}
{{ 'styles.css'|static }} might become "http://mycdn.example.com/styles.css"
{%- endraw %}
see app/templates.index.jinja for usage.
:param context: see http://jinja.pocoo.org/docs/dev/api/#jinja2.contextfilter
:param static_file_path: path to static file under static route
:return: roughly just "<static_root_url>/<static_file_path>"
"""
app = context['app']
try:
static_url = app['static_root_url']
except KeyError:
raise RuntimeError('app does not define a static root url "static_root_url"')
return '{}/{}'.format(static_url.rstrip('/'), static_file_path.lstrip('/'))
# {% endif %}
# {% if database.is_pg_sqlalchemy %}
评论列表
文章目录