Google App Engine add image to page with static fo

2019-08-01 07:11发布

i have a problem to use image with static folder path in my page. this is my app.yaml

application: something
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /images
  static_dir: static/images

- url: /favicon.ico
  static_files: static/favicon.ico
  upload: static/favicon.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest

I have templates, static/images, controllers (has MainHandler.py) folders and in my root i have main.py and app.yaml files. in my templeate folder i have index.html file that contain:

<div>
    <img src="images/fig1.jpg">
</div>

my problem is when page was loaded i cant see my fig1.jpg picture.

1条回答
beautiful°
2楼-- · 2019-08-01 07:37

What is the url of this page? If it looks like a subdirectory, then your using a relative path for your image is not pointing to the images path. Try changing to:

<div>
    <img src="/images/fig1.jpg">
</div>

If using Windows, there is a known bug. See:

Google App Engine: Won't serve static assets with below error:

Try adding mime_type: "image/jpeg" to your image handler, to see if that is the cause.

查看更多
登录 后发表回答