-->

Unable to see image on Google app engine web

2019-08-09 20:04发布

问题:

I Just want to show image on Google app Engine Website. I am new to Google app engine. I made changes in App.yaml and Main.py app.yaml looks like :

application: simplegraph-007
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
 static_files: favicon.ico
 upload: favicon\.ico

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

- url: .*
  script: main.app

 libraries:
 - name: webapp2
  version: "2.5.2"

Main.py looks like.

import webapp2

class MainHandler(webapp2.RequestHandler):
def get(self):
    self.response.out.write("""<img src = 'D:\download\rel.png/>""")

app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)

What else I need to change. I hope to get help.

Thanks,

回答1:

Copy the image to static/images directory in your project. From a browser, this path is "/images".

If you just want to show the image, in your browser, go to: http://localhost:8080/images/rel.png

To see the image from the cloud, deploy your app and see the image at: http://PROJECT_ID.appspot.com/images/rel.png

To use that image within an html page, use:

<img src="/images/rel.png" />


回答2:

You are outputting invalid HTML. It is missing the closing single quote ' and has an extra trailing /.

<img src = 'D:\download\rel.png/>

Also you are trying to serve an image directly from your filesystem which may work locally, but it will not work when deployed to app engine.