瓶子显示图像使用文件://

2024-09-30 14:24:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在本地计算机上显示图像。我只使用我自己机器上的网站。我不指望外面来拜访。我在这里找到了一个解决方案:Get Flask to show image not located in the static directory,但它对我不起作用。我试过:

相对路径,abs路径。他们都不管用。我哪里做错了?在

问题: 出于测试目的,我的文件系统如下:

C:/jackson/Python34_workspace/Python34_Projects/Learn-Bottle/app05_rend_local_img/
    picuture_gallery/Desert.jpg
    views/index.tpl
    main.py

python脚本是这样的

^{pr2}$

这是我的模板。在

<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"

单击“提交”后,它不会显示。但是如果我把它拖到浏览器上,它就可以工作了。怎么可能呢?在


Tags: brformbottleimglocalgallerylearnworkspace
1条回答
网友
1楼 · 发布于 2024-09-30 14:24:48

使用file协议的URL是从服务器请求的。客户端(浏览器)总是在本地系统上查找它。在

因此,无论你如何配置瓶子应用程序,浏览器都不会要求它提供这样的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')

相关问题 更多 >