tangyuan
V2EX  ›  问与答

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

  •  
  •   tangyuan · Jul 25, 2013 · 5518 views
    This topic created in 4684 days ago, the information mentioned may be changed or developed.
    - 主程序放在根目录下
    - 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 replies    1970-01-01 08:00:00 +08:00
    timonwong
        1
    timonwong  
       Jul 25, 2013   ❤️ 1
    root='/'
    改为你about.png 所在路径
    tangyuan
        2
    tangyuan  
    OP
       Jul 25, 2013
    @timonwong 感谢!原来要这样写,./static/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1075 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:18 · PVG 07:18 · LAX 16:18 · JFK 19:18
    ♥ Do have faith in what you're doing.