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













0















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.










share|improve this question




























    0















    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.










    share|improve this question


























      0












      0








      0








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 20:29









      davidism

      65.4k12175189




      65.4k12175189










      asked Mar 7 at 20:25









      HimaHima

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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.






          share|improve this answer























          • 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










          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
          );



          );













          draft saved

          draft discarded


















          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









          0














          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.






          share|improve this answer























          • 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















          0














          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.






          share|improve this answer























          • 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













          0












          0








          0







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived