I trying to learn web application development. I’m currently using Google App Engine to create apps. 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 -‘. When I ran dev_appserver it showed a warning saying I needed the python module “PIL” to do imaging. 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————
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. Try the following …
Also, make sure your image files are under the directory images as you specified in static_dir.
Hope this helps.