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

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page