python flask - serving static files

后端 未结 2 1442
灰色年华
灰色年华 2021-01-02 01:16

I\'m trying to serve a static file using flask. I don\'t know how to use the url_for function. All my routes generating dynamic content are working fine, I\'ve imported url_

2条回答
  •  情话喂你
    2021-01-02 01:36

    url_for just returns, precisely, the URL for that file. It sounds like you want to redirect to the URL for that file. Instead, you are just sending the text of the URL to the client as a response.

    from flask import url_for, redirect
    
    @app.route('/')
    def home():
        return redirect(url_for('static', filename='hi.html'))
    

提交回复
热议问题