瓶子显示图像使用 File://
Bottle Display Image using File://
我正在尝试在本地计算机上显示图像。我只在我自己的机器上使用网站。我不期待来自外面的访问。我在这里找到了解决方案:Get Flask to show image not located in the static directory,但它对我不起作用。我试过:
相对路径,绝对路径。 None 其中有效。我哪里做错了?
问题:
出于测试目的,我的文件系统是这样的:
C:/jackson/Python34_workspace/Python34_Projects/Learn-Bottle/app05_rend_local_img/
picuture_gallery/Desert.jpg
views/index.tpl
main.py
python脚本是这个
@bottle.route("/")
def index():
return bottle.template("index.tpl")
@bottle.post('/result')
def result():
return bottle.template("index.tpl")
这是我的模板。
<form action="/result" method="POST">
<br>
<input type="submit" value="Submit">
<br>
</form>
<div>
<img src="file:///C:/HSH/Python34_workspace/Python34_Projects/Learn-Bottle/app05_rend_local_img/picture_gallery/Desert.jpg">
</div>
--- 一些评论 ---
我试过了
src="file:///picuture_gallery/Desert.jpg"
点击提交后,没有显示。但是,如果我将它拖到浏览器中,它就可以工作。怎么可能?
使用 file
协议的 URL 从未 从服务器请求。客户端(浏览器)总是在本地系统上寻找它。
因此,无论您如何配置 Bottle 应用程序,浏览器都不会要求它提供这样的 URL。
如果您希望 Botte 应用程序 deliver static files,请执行以下操作:
from bottle import static_file
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='/path/to/your/static/files')
我正在尝试在本地计算机上显示图像。我只在我自己的机器上使用网站。我不期待来自外面的访问。我在这里找到了解决方案:Get Flask to show image not located in the static directory,但它对我不起作用。我试过:
相对路径,绝对路径。 None 其中有效。我哪里做错了?
问题: 出于测试目的,我的文件系统是这样的:
C:/jackson/Python34_workspace/Python34_Projects/Learn-Bottle/app05_rend_local_img/
picuture_gallery/Desert.jpg
views/index.tpl
main.py
python脚本是这个
@bottle.route("/")
def index():
return bottle.template("index.tpl")
@bottle.post('/result')
def result():
return bottle.template("index.tpl")
这是我的模板。
<form action="/result" method="POST">
<br>
<input type="submit" value="Submit">
<br>
</form>
<div>
<img src="file:///C:/HSH/Python34_workspace/Python34_Projects/Learn-Bottle/app05_rend_local_img/picture_gallery/Desert.jpg">
</div>
--- 一些评论 --- 我试过了
src="file:///picuture_gallery/Desert.jpg"
点击提交后,没有显示。但是,如果我将它拖到浏览器中,它就可以工作。怎么可能?
使用 file
协议的 URL 从未 从服务器请求。客户端(浏览器)总是在本地系统上寻找它。
因此,无论您如何配置 Bottle 应用程序,浏览器都不会要求它提供这样的 URL。
如果您希望 Botte 应用程序 deliver static files,请执行以下操作:
from bottle import static_file
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='/path/to/your/static/files')