【问题标题】:Web.py not serving static filesWeb.py 不提供静态文件
【发布时间】:2015-04-26 15:14:15
【问题描述】:

在开发服务器上运行,我可以在没有 CSS 的情况下渲染 0.0.0.0:8080/index.html,但不会加载静态文件。 0.0.0.0:8080/static 导致“未找到”并且 0.0.0.0:8080/static/style.css 得到 404。

我在 Google 上搜索到的所有引用或链接都指向了 http://webpy.org/cookbook/staticfiles,我觉得我已经遵循了这一点。

文件树

code.py
/web
    ...
/static
    style.css
    /images
        ...
/pages
    index.html

code.py

import web

render = web.template.render('/home/keith/code/webpy/skeleton/pages/')

urls = (
    '/', 'index',)

class index:
    def GET(self):
        return render.index()

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

/pages/index.html

...
<link rel="stylesheet" type="text/css" href="static/style.css" />
...

不胜感激!

【问题讨论】:

    标签: python web.py


    【解决方案1】:

    我尝试从终端窗口运行python code.py,静态文件运行良好!之前,我在我的 IDE (Geany 1.24.1) 中使用终端仿真器。所以这就是问题所在,无论出于何种原因。

    【讨论】:

      猜你喜欢
      • 2012-06-08
      • 2012-06-15
      • 2018-10-23
      • 2021-07-08
      • 2013-06-02
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多