Flask: How to serve static html?

前端 未结 3 736
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 05:35

I am trying to serve a static html file, but returns a 500 error (a copy of editor.html is on .py and templates directory) This is all I have tried:

from fla         


        
3条回答
  •  情话喂你
    2020-12-06 06:06

    All the answers are good but what worked well for me is just using the simple function send_file from Flask. This works well when you just need to send an html file as response when host:port/ApiName will show the output of the file in browser

    
    @app.route('/ApiName')
    def ApiFunc():
        try:
            #return send_file('relAdmin/login.html')
            return send_file('some-other-directory-than-root/your-file.extension')
        except Exception as e:
            logging.info(e.args[0])```
    
    

提交回复
热议问题