Unable to retrieve files from send_from_directory() in flask

前端 未结 5 820
忘掉有多难
忘掉有多难 2020-12-09 16:47

I have a html file which references static object like this



         


        
5条回答
  •  一个人的身影
    2020-12-09 17:26

    I think a better way to do this would be:

    import flask
    
    # ...
    
    @app.route('/img/')
    def legacy_images(fname):
        return flask.redirect(flask.url_for('static', filename='img/' + fname), code=301)
    

    Instead of sending the files on two different locations, this would do a permanent redirect to the proper URL. As others have said, it's also a good idea to serve static files directly with nginx or Apache.

提交回复
热议问题