Flask script url_for not found [duplicate]
This question already has an answer here:
How can I pass data from Flask to JavaScript in a template?
8 answers
Pass parameter with Python Flask in external Javascript
2 answers
I have a problem. Flask application respond a 404 not found at this .css url.
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");
}
javascript python flask jinja2
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I pass data from Flask to JavaScript in a template?
8 answers
Pass parameter with Python Flask in external Javascript
2 answers
I have a problem. Flask application respond a 404 not found at this .css url.
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");
}
javascript python flask jinja2
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I pass data from Flask to JavaScript in a template?
8 answers
Pass parameter with Python Flask in external Javascript
2 answers
I have a problem. Flask application respond a 404 not found at this .css url.
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");
}
javascript python flask jinja2
This question already has an answer here:
How can I pass data from Flask to JavaScript in a template?
8 answers
Pass parameter with Python Flask in external Javascript
2 answers
I have a problem. Flask application respond a 404 not found at this .css url.
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");
}
This question already has an answer here:
How can I pass data from Flask to JavaScript in a template?
8 answers
Pass parameter with Python Flask in external Javascript
2 answers
javascript python flask jinja2
javascript python flask jinja2
edited Jan 2 at 12:48


deHaar
2,60051729
2,60051729
asked Jan 2 at 12:02


spehlivanspehlivan
11
11
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 13:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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'))
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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'))
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
add a comment |
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'))
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
add a comment |
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'))
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'))
edited Jan 3 at 8:00
answered Jan 2 at 12:42
Arthur HavlicekArthur Havlicek
787411
787411
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
add a comment |
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
I learned a new thing thank you very much. its worked
– spehlivan
Jan 2 at 13:13
add a comment |