adding flask expression using url_for dynamically in javascript to display a img elementHow can I merge properties of two JavaScript objects dynamically?Event binding on dynamically created elements?Remove empty elements from an array in JavascriptHow do you access the matched groups in a JavaScript regular expression?Deleting array elements in JavaScript - delete vs spliceHow can I display a JavaScript object?How do I remove a particular element from an array in JavaScript?Create dynamic URLs in Flask with url_for()How can I add new array elements at the beginning of an array in Javascript?Cannot display HTML string
How do I prevent inappropriate ads from appearing in my game?
Did I make a mistake by ccing email to boss to others?
How do you say "Trust your struggle." in French?
How to preserve electronics (computers, ipads, phones) for hundreds of years?
New Order #2: Turn My Way
Why can't I get pgrep output right to variable on bash script?
Can you describe someone as luxurious? As in someone who likes luxurious things?
What is it called when someone votes for an option that's not their first choice?
Can you take a "free object interaction" while incapacitated?
Has the laser at Magurele, Romania reached a tenth of the Sun's power?
Air travel with refrigerated insulin
What do the positive and negative (+/-) transmit and receive pins mean on Ethernet cables?
Why didn't Voldemort know what Grindelwald looked like?
1 John in Luther’s Bibel
When is the exact date for EOL of Ubuntu 14.04 LTS?
Calculate Pi using Monte Carlo
How would a solely written language work mechanically
Is this saw blade faulty?
Put the phone down / Put down the phone
Why didn’t Eve recognize the little cockroach as a living organism?
Reason why a kingside attack is not justified
Showing mass murder in a kid's book
Why does a 97 / 92 key piano exist by Bosendorfer?
What is the purpose of using a decision tree?
adding flask expression using url_for dynamically in javascript to display a img element
How can I merge properties of two JavaScript objects dynamically?Event binding on dynamically created elements?Remove empty elements from an array in JavascriptHow do you access the matched groups in a JavaScript regular expression?Deleting array elements in JavaScript - delete vs spliceHow can I display a JavaScript object?How do I remove a particular element from an array in JavaScript?Create dynamic URLs in Flask with url_for()How can I add new array elements at the beginning of an array in Javascript?Cannot display HTML string
I am trying to append a img element in ajax POST request success for my flask application as below:
$.ajax({
type: "POST",
url: "/image",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(pred_path),
success: function()
$('span#predimage').append("<img src=' url_for('new_send') ' width='1140' height='700'>");
error: function(request,status,message)
//alert("Errorn"+message);
);
The element is called correctly and the output in HTML element looks like below:
<span id="predimage"><img src=" url_for(" new_send')="" '="" height="700" width="1140"></span>
Because of which the image is not getting displayed on the webpage. can someone please help me here as i couldn't find any proper solution . Reference for the above is taken from https://www.reddit.com/r/flask/comments/6di61d/url_for_and_jqueryjavascript/ which says the similar usage worked. But i cannot understand why it is not working here.
javascript python flask
add a comment |
I am trying to append a img element in ajax POST request success for my flask application as below:
$.ajax({
type: "POST",
url: "/image",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(pred_path),
success: function()
$('span#predimage').append("<img src=' url_for('new_send') ' width='1140' height='700'>");
error: function(request,status,message)
//alert("Errorn"+message);
);
The element is called correctly and the output in HTML element looks like below:
<span id="predimage"><img src=" url_for(" new_send')="" '="" height="700" width="1140"></span>
Because of which the image is not getting displayed on the webpage. can someone please help me here as i couldn't find any proper solution . Reference for the above is taken from https://www.reddit.com/r/flask/comments/6di61d/url_for_and_jqueryjavascript/ which says the similar usage worked. But i cannot understand why it is not working here.
javascript python flask
add a comment |
I am trying to append a img element in ajax POST request success for my flask application as below:
$.ajax({
type: "POST",
url: "/image",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(pred_path),
success: function()
$('span#predimage').append("<img src=' url_for('new_send') ' width='1140' height='700'>");
error: function(request,status,message)
//alert("Errorn"+message);
);
The element is called correctly and the output in HTML element looks like below:
<span id="predimage"><img src=" url_for(" new_send')="" '="" height="700" width="1140"></span>
Because of which the image is not getting displayed on the webpage. can someone please help me here as i couldn't find any proper solution . Reference for the above is taken from https://www.reddit.com/r/flask/comments/6di61d/url_for_and_jqueryjavascript/ which says the similar usage worked. But i cannot understand why it is not working here.
javascript python flask
I am trying to append a img element in ajax POST request success for my flask application as below:
$.ajax({
type: "POST",
url: "/image",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(pred_path),
success: function()
$('span#predimage').append("<img src=' url_for('new_send') ' width='1140' height='700'>");
error: function(request,status,message)
//alert("Errorn"+message);
);
The element is called correctly and the output in HTML element looks like below:
<span id="predimage"><img src=" url_for(" new_send')="" '="" height="700" width="1140"></span>
Because of which the image is not getting displayed on the webpage. can someone please help me here as i couldn't find any proper solution . Reference for the above is taken from https://www.reddit.com/r/flask/comments/6di61d/url_for_and_jqueryjavascript/ which says the similar usage worked. But i cannot understand why it is not working here.
javascript python flask
javascript python flask
edited Mar 7 at 20:29
davidism
65.4k12175189
65.4k12175189
asked Mar 7 at 20:25
HimaHima
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to understand that flask is a Backend framework.
This means that when a Client makes a request for a page, flask will take care of rendering such page and returning it to the client.
Functions like "url_for" are pretty useful to personalize your page when it is rendering.
With this said, after flask returns the rendered page, he has no way of changing anything on it.
When you add the "url_for" on JavaScript your are adding it on an already rendered page. This happens in client-side and flask is not aware of this.
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052257%2fadding-flask-expression-using-url-for-dynamically-in-javascript-to-display-a-img%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to understand that flask is a Backend framework.
This means that when a Client makes a request for a page, flask will take care of rendering such page and returning it to the client.
Functions like "url_for" are pretty useful to personalize your page when it is rendering.
With this said, after flask returns the rendered page, he has no way of changing anything on it.
When you add the "url_for" on JavaScript your are adding it on an already rendered page. This happens in client-side and flask is not aware of this.
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
add a comment |
You need to understand that flask is a Backend framework.
This means that when a Client makes a request for a page, flask will take care of rendering such page and returning it to the client.
Functions like "url_for" are pretty useful to personalize your page when it is rendering.
With this said, after flask returns the rendered page, he has no way of changing anything on it.
When you add the "url_for" on JavaScript your are adding it on an already rendered page. This happens in client-side and flask is not aware of this.
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
add a comment |
You need to understand that flask is a Backend framework.
This means that when a Client makes a request for a page, flask will take care of rendering such page and returning it to the client.
Functions like "url_for" are pretty useful to personalize your page when it is rendering.
With this said, after flask returns the rendered page, he has no way of changing anything on it.
When you add the "url_for" on JavaScript your are adding it on an already rendered page. This happens in client-side and flask is not aware of this.
You need to understand that flask is a Backend framework.
This means that when a Client makes a request for a page, flask will take care of rendering such page and returning it to the client.
Functions like "url_for" are pretty useful to personalize your page when it is rendering.
With this said, after flask returns the rendered page, he has no way of changing anything on it.
When you add the "url_for" on JavaScript your are adding it on an already rendered page. This happens in client-side and flask is not aware of this.
answered Mar 7 at 21:25
asergioasergio
863
863
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
add a comment |
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
Thanks very much for above asergio. In that case, when I'm trying to give SRC="file:///programming/......" On the HTML page, image is not getting rendered as well. But the same path mentioned above opens the image when given in webpage. Please help me as I m new to flask and web development.
– Hima
Mar 7 at 22:44
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
This really depends on you are trying to do. Anyway, you should start by making flask serve static files. Make sure you have the image you want inside the static folder on your project and test if flask is serving it to you by requesting its path "localhost:5000/static/myimage.jpg". If it works, you simply have to use this path on the SRC of your image.
– asergio
Mar 7 at 22:55
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
Sorry for trouble but I don't want to serve from static folder. Yes, my application worked with static but I have absolute paths of images located in a shared server. I want to access those files from my flask application.
– Hima
Mar 7 at 23:22
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
I am having trouble to understand clearly your situation. I think this problem deserves a new question where you share the code you have right now and the tree of your project files.
– asergio
Mar 7 at 23:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052257%2fadding-flask-expression-using-url-for-dynamically-in-javascript-to-display-a-img%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown