本地文件的put_link链接的问题 #174
Unanswered
yangbanhong
asked this question in
Q&A
Replies: 1 comment 3 replies
-
由于浏览器安全性的限制,是无法使用本地路径作为URL指向本地文件的。 如果你是想实现点击链接下载文件的效果,可以使用 content = open(r'D:\python\progressbar.vsd', 'rb').read()
put_file('progressbar.vsd', content=content, 'visio file') 如果是想点击链接后在浏览器打开该文件(前提是浏览器支持预览该文件类型)的话,需要将该文件转换成网络文件,然后使用网络URL引用: from pywebio.output import *
from pywebio import start_server
def main():
# static_dir文件夹下的文件使用 /static/... 来引用
put_link('link to some file', url=r'/static/some.file', new_window=False)
if __name__ == '__main__':
# 将需要在浏览器打开的文件放入static_dir指定的文件夹
start_server(main, port=8080, static_dir='/path/to/your/static/dir') |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
你好,我用put_link设置了一个本地的visio的文件,点击链接后没有反应,请问这个问题可以解决吗?浏览器是Edge。
谢谢!
`from pywebio.output import *
put_link('visio file', url=r'D:\python\progressbar.vsd',new_window=False)`
Beta Was this translation helpful? Give feedback.
All reactions