0

I have a problem. Flask application respond a 404 not found at this .css url.

enter image description here

How can I write this jinja code in javascript file ?

{{ url_for('static', filename='assets/css/themes/') }}

Javascript file

var setColor = function (color) {
            var color_ = (App.isRTL() ? color + '-rtl' : color);
            $('#style_color').attr("href", "assets/css/themes/" + color_ + ".css");
        }
0

1 Answer 1

0

Jinja 2 is expected to template html files only : unless you put your script in the html and template it, which I would discourage, you cannot use templating directly in your javascript static file.

You can however template a part of the html that will contain the link, for example in a data attribute, or in a shared variable, to be recovered by javascript.

In the page

<div id="mydiv" data-myurl='{{ url_for('static', filename='assets/css/themes/') }}'> </div>

In javascript

 $('#style_color').attr("href", $("#mydiv").data('myurl'))
Sign up to request clarification or add additional context in comments.

1 Comment

I learned a new thing thank you very much. its worked

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.