开发者

Unable to Display image in Google App Engine (Python)

开发者 https://www.devze.com 2022-12-27 10:12 出处:网络
I am unable to display images in pages created using Google App Engine(Python). My app.yaml file has :

I am unable to display images in pages created using Google App Engine(Python).

My app.yaml file has :

- url: /images
  static_dir: images

And the python file has:

self.response.out.write("""<img src = '/images/title.gif' />""")  

The image still does not display in开发者_StackOverflow社区 the page.

Thanks


I would test:

  1. Do you see http://yourapp.appspot.com/images/title.gif?
  2. Are you sure that images folder is on your app root?
  3. Title.gif is a "working" image?

I would recommend you to use a static folder to store your static contents organized in subfolders:

Root  
  static  
     images
     stylesheets
     javascripts
  app.yaml

and Mapping a url /images like this.

- url: /images
  static_dir: static/images
  mime_type: image/png 

mime_type: image/png is optional; if not specified, the MIME type for a file will be derived from the file's filename extension.


I encountered a similar problem. The solution was ultimately very simple. You need to try to reposition the url handler for the static directory before the apphandler for the main.app like this:

handlers:

  • url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico
  • url: /photos static_dir: photos
  • url: .* script: main.app

This annoyed me for like 45 min before I found the solution on google.


Is there a directory called 'images' in your app's root directory? What does it contain? What do you get if you attempt to fetch the file directly?


The reason may be about upper/lower case difference between systems. Windows is not upper/lower sensitive, but Linux is. Supposing your actual file name is Title.GIF. It works if it is written as title.gif on a Windows machine (Your Local machine), but does not work on a Linux server (Google App Server).


One possible reason for this to happen is if you do not provide space between - url and if you do not restart your server. It will show 404 that time. If you restart your server then you will encounter the error in app.yaml. This is one very common mistake that people commit. Because the way you have done it seems that it should work fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消