Flask script url_for not found [duplicate]












0
















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.



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









share|improve this question















marked as duplicate by davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

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.























    0
















    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.



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









    share|improve this question















    marked as duplicate by davidism flask
    Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

    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.





















      0












      0








      0









      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.



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









      share|improve this question

















      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.



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




      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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 flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      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 flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      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.


























          1 Answer
          1






          active

          oldest

          votes


















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





          share|improve this answer


























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

            – spehlivan
            Jan 2 at 13:13




















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









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





          share|improve this answer


























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

            – spehlivan
            Jan 2 at 13:13


















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





          share|improve this answer


























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

            – spehlivan
            Jan 2 at 13:13
















          0












          0








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





          share|improve this answer















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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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





















          • 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







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith