Issue
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_for, but when I have this code:
@app.route('/')
def home():
return url_for('static', filename='hi.html')
Along with my 'hi.html' file (which has some basic html in it) sitting in directory static, what I get when I load the page is literally this:
/static/hi.html
Am I just using url_for incorrectly?
Solution
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'))
Answered By - Michael Greene
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.