【发布时间】:2012-12-04 14:05:04
【问题描述】:
谁能大致指出在 python sdk 代码中静态路由被加载到 http_server 或被 http_server 访问的大致位置。这是为了调试加载静态图像失败。在 Eclipse 中,我可以看到静态路由从 yaml 文件加载到 var appinfo 中,稍后可以看到在请求期间检查动态路由,但在执行中间步骤时遇到问题。 谢谢
11/30 更新
以前尝试过一些文档和帖子中建议的 yaml、路径等变体。 这是其中之一。在这种情况下,没有 404 错误,但图像不会加载并且 Firebug 报告“加载给定 URL 失败”。
app.yaml
application: crazywidget2
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /images
static_dir: /images
secure: always
-url: /.*
script: crazywidget2.py
secure: always
libraries:
- name: jinja2
version: latest
index.html
...
<img src="/images/xyz.gif" alt="XYZ illustration" />
...
crazywidget2.py
>...
class MainPage(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render({}))
...
...
app = webapp2.WSGIApplication([('/script_send', ScriptSend),
('/resetkey', ResetKey),
('/admin', Admin),
('/start', Start),
('/', MainPage)],
debug=True)
def main():
app.run()
if __name__=='__main__':
main()
12/3 更新
事实证明,在上述情况下,如果 static_dir 是相对的,“images”而不是“/images”,它就可以工作。在绝对情况下,它会尝试按原样打开该路径。也许其他一些变化也可以。
【问题讨论】: