python烧瓶 - 提供静态文件 [英] python flask - serving static files
问题描述
@app。 route('/')
def home():
return url_for('static',filename ='hi.html')
与我坐在静态目录中的'hi.html'文件(里面有一些基本的html)一起,当我加载页面的时候,字面上是这样的: p>
/static/hi.html
我只是使用url_for不正确?
url_for
该文件的URL。这听起来像你想重定向
到该文件的URL。相反,您只是将URL的文本作为响应发送给客户端。
from flask import url_for,redirect
@ app.route('/')
def home():
return redirect(url_for('static',filename ='hi.html'))
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?
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'))
这篇关于python烧瓶 - 提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!