简体   繁体   English

Google App Engine,上传图片

[英]Google App Engine, Uploading Images

I trying to learn web application development. 我试图学习Web应用程序开发。 I'm currently using Google App Engine to create apps. 我目前正在使用Google App Engine创建应用。 I was experimenting with showing images on my site but the site just shows the alternate text. 我正在尝试在网站上显示图像,但该网站仅显示替代文本。

The first time I tried this I didn't know about static files. 第一次尝试这样做,我对静态文件一无所知。 Once I fixed that problem the request line for the image showed: '"GET /images/pic.jpg HTTP/1.1" 200 -'. 解决此问题后,图片的请求行显示为:““ GET /images/pic.jpg HTTP / 1.1” 200-“。 When I ran dev_appserver it showed a warning saying I needed the python module "PIL" to do imaging. 当我运行dev_appserver时,它显示警告,说我需要python模块“ PIL”进行映像。 Once I downloaded and installed that the warning disappeared but it still won't load the picture! 下载并安装该警告后,该警告消失了,但仍然无法加载图片! The request line still shows that it found the image. 请求行仍然显示它找到了图像。 But all the site displays is the alternate text! 但是,所有站点显示的都是替代文本!

Anyway, here's the code for the app.yaml and script: (note: I'm using the code for python 2.5) 无论如何,这是app.yaml和脚本的代码:(注意:我正在使用python 2.5的代码)

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

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

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

- url: /images
  static_dir: images

---------- script ----------- ----------脚本-----------

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

Here's what my application directory looks like: 这是我的应用程序目录的样子:

Root

   app.yaml

   script.py

   images

      pic.jpg

I recently found out that even if I change the name of the images directory in my script 我最近发现,即使我在脚本中更改了图像目录的名称,

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

the request line still says its OK 请求行仍然说可以

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

Anybody know what's going on? 有人知道发生了什么吗?

The order of your handlers matter. 处理程序的顺序很重要。 /.* matches every URI, hence you typically want that at the end. /.*匹配每个URI,因此通常希望在末尾使用。 Try the following ... 尝试以下方法...

handlers:
- url: /images
  static_dir: images

- url: /.*
  script: myscript.py

Also, make sure your image files are under the directory images as you specified in static_dir. 另外,请确保您的图像文件位于static_dir中指定的目录图像下。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM