【问题标题】:Google App Engine, Uploading ImagesGoogle App Engine,上传图片
【发布时间】:2012-05-12 02:40:25
【问题描述】:

我正在尝试学习 Web 应用程序开发。我目前正在使用 Google App Engine 来创建应用程序。我正在尝试在我的网站上显示图片,但该网站只显示替代文字。

我第一次尝试这个时,我不知道静态文件。一旦我解决了这个问题,图像的请求行就会显示:'"GET /images/pic.jpg HTTP/1.1" 200 -'。当我运行 dev_appserver 时,它显示一条警告说我需要 python 模块“PIL”来进行成像。一旦我下载并安装,警告就消失了,但它仍然不会加载图片!请求行仍然显示它找到了图像。但网站显示的只是替代文字!

无论如何,这是 app.yaml 和脚本的代码: (注意:我使用的是 python 2.5 的代码)

-----------app.yaml------------

application: mysite
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: myscript.py

- url: /images
  static_dir: images

--------- 脚本------------

template = """
        <body>
                <br>
                <br>
                <img src="/images/pic.jpg" alt="Clone Pic" width="100", height="70"/><br>
        </body>
"""
print "Content-Type: text/html"
print template

这是我的应用程序目录的样子:

Root

   app.yaml

   script.py

   images

      pic.jpg

我最近发现,即使我在脚本中更改了图像目录的名称

<img src="/foo/pic.jpg...)

请求行仍然显示正常

"GET /foo/pic.jpg HTTP/1.1" 200 -

有人知道怎么回事吗?

【问题讨论】:

    标签: python html google-app-engine


    【解决方案1】:

    处理程序的顺序很重要。 /.* 匹配每个 URI,因此您通常希望在最后。试试下面的...

    handlers:
    - url: /images
      static_dir: images
    
    - url: /.*
      script: myscript.py
    

    另外,请确保您的图像文件位于您在 static_dir 中指定的目录 images 下。

    希望这会有所帮助。

    【讨论】:

    • 谢谢!这解决了问题!
    猜你喜欢
    • 2015-02-07
    • 2013-09-14
    • 2012-09-05
    • 2013-07-13
    • 1970-01-01
    • 2010-09-14
    • 2013-08-25
    • 2013-04-07
    • 1970-01-01
    相关资源
    最近更新 更多