Y
Y
YaroslavS2015-08-11 16:33:57
Flask
YaroslavS, 2015-08-11 16:33:57

Is it possible to dynamically include static files in a jinja2 template?

Hello, I am writing an application in flask. The essence of the problem.
It is necessary to dynamically connect a static file to the jinja2 template, the path to which is not known at the time of template creation.

<link href="{{ url_for('.static', filename=' ') }}" rel="stylesheet">

filename=' ' here you need to dynamically add the path to the style sheet. Same with js files
, is there any solution other than inline addition?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-08-12
@YaroslavS

Well, pass the filename variable to the template, and substitute it in url_for. Not that?
You can define your variables in the template using the {% set filename = 'css_' + form.media.css %} construct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question