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:
- Do you see http://yourapp.appspot.com/images/title.gif?
- Are you sure that images folder is on your app root?
- 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\.icostatic_files:favicon.icoupload:favicon\.ico - url:
/photosstatic_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.
加载中,请稍侯......
精彩评论