V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tangyuan
V2EX  ›  问与答

Python Bottle 要如何才能显示静态文件(图片)啊,看了官方教程弄不出来特来求助

  •  
  •   tangyuan · 2013-07-25 15:39:40 +08:00 · 5050 次点击
    这是一个创建于 3936 天前的主题,其中的信息可能已经有所发展或是发生改变。
    - 主程序放在根目录下
    - about.png图片文件放在static文件夹中

    主程序代码
    from bottle import static_file, route, run
    @route('/static/<filename>')
    def server_static(filename):
    filename +=".png"
    return static_file(filename, root='/')

    run(host='0.0.0.0', port='8080')

    访问路径http://10.30.5.18:8080/static/about

    报错Error: 404 Not Found
    2 条回复    1970-01-01 08:00:00 +08:00
    timonwong
        1
    timonwong  
       2013-07-25 16:06:29 +08:00   ❤️ 1
    root='/'
    改为你about.png 所在路径
    tangyuan
        2
    tangyuan  
    OP
       2013-07-25 16:21:07 +08:00
    @timonwong 感谢!原来要这样写,./static/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1065 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 18:19 · PVG 02:19 · LAX 11:19 · JFK 14:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.