0

我的app.yaml

handlers:
  - url: /static
    static_dir: static

  - url: /.*
    script: main.app

有没有办法在我的 webapp2 代码中获取/static路由的绝对 URL?

4

2 回答 2

1

在应用程序中定义路由时,您可以计算 uri。请参阅:http ://webapp-improved.appspot.com/guide/routing.html#building-uris 有了这些信息和您对 app.yaml 的了解,您可以计算静态 url 的 uri。

在您的 main.app 中,您为静态添加了一个虚拟路由定义。它只会用于构建 uri,永远不会用于路由。

来自 webapp2 文档的修改示例:

app = webapp2.WSGIApplication([
    webapp2.Route('/', handler='HomeHandler', name='home'),
    webapp2.Route('/static', handler=HomeHandler, name='static'), # never used for routing
])
于 2012-09-27T19:55:05.973 回答
0

不,没有办法查询、循环或找出作为静态上传的文件夹中的内容。

但只要您不使用新的静态文件部署应用程序,静态文件就不会更改。

您需要保留静态文件并自己编写这些绝对网址

于 2012-09-27T19:37:18.587 回答