How to access local file in Flask? [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1
















This question already has an answer here:




  • How to serve static files in Flask

    13 answers




I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.



File directory:



-Flask
-static/
--some js
-template/
--some HTML
-logs/
--log1.log
--log2.log
--...
app.py


I access the file in HTML as



 localhost:port/logs/log1.log


But the web gives me a 404.



How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?



Thanks.










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 4 at 14:43


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
















    This question already has an answer here:




    • How to serve static files in Flask

      13 answers




    I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.



    File directory:



    -Flask
    -static/
    --some js
    -template/
    --some HTML
    -logs/
    --log1.log
    --log2.log
    --...
    app.py


    I access the file in HTML as



     localhost:port/logs/log1.log


    But the web gives me a 404.



    How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?



    Thanks.










    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 4 at 14:43


    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












      -1








      -1









      This question already has an answer here:




      • How to serve static files in Flask

        13 answers




      I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.



      File directory:



      -Flask
      -static/
      --some js
      -template/
      --some HTML
      -logs/
      --log1.log
      --log2.log
      --...
      app.py


      I access the file in HTML as



       localhost:port/logs/log1.log


      But the web gives me a 404.



      How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?



      Thanks.










      share|improve this question















      This question already has an answer here:




      • How to serve static files in Flask

        13 answers




      I want to access the local file using a hyperlink from the web using Flask. My file directory and what I have tried is as follows.



      File directory:



      -Flask
      -static/
      --some js
      -template/
      --some HTML
      -logs/
      --log1.log
      --log2.log
      --...
      app.py


      I access the file in HTML as



       localhost:port/logs/log1.log


      But the web gives me a 404.



      How could I access the file? I am not very sure about the route in Flask. Could you give me some reference?



      Thanks.





      This question already has an answer here:




      • How to serve static files in Flask

        13 answers








      flask routes






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 4 at 4:54









      Elegant LinElegant Lin

      62




      62




      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 4 at 14:43


      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 4 at 14:43


      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














          You can use send_from_directory function in flask to send static files
          This might help you
          @app.route('/logs/<path:filename>')
          def download_file(filename):
          return send_from_directory("/logs/",
          filename, as_attachment=True)






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can use send_from_directory function in flask to send static files
            This might help you
            @app.route('/logs/<path:filename>')
            def download_file(filename):
            return send_from_directory("/logs/",
            filename, as_attachment=True)






            share|improve this answer




























              0














              You can use send_from_directory function in flask to send static files
              This might help you
              @app.route('/logs/<path:filename>')
              def download_file(filename):
              return send_from_directory("/logs/",
              filename, as_attachment=True)






              share|improve this answer


























                0












                0








                0







                You can use send_from_directory function in flask to send static files
                This might help you
                @app.route('/logs/<path:filename>')
                def download_file(filename):
                return send_from_directory("/logs/",
                filename, as_attachment=True)






                share|improve this answer













                You can use send_from_directory function in flask to send static files
                This might help you
                @app.route('/logs/<path:filename>')
                def download_file(filename):
                return send_from_directory("/logs/",
                filename, as_attachment=True)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 4 at 7:02









                Deepam PatelDeepam Patel

                1015




                1015

















                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas