Having a hard time to upload and display image in python gae.
Here is what I did.
1. in the app.yaml file, I added:
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /(.*\.(gif|png|jpg))
static_files: /\1
upload: (.*\.(gif|png|jpg))
- url: .*
script: main.app
- Then put down:
in
def Character(db.Model):
avatar = db.BlobProperty()
under my handler:
if avatar:
character_info.avatar = db.Blob(images.resize(avatar, 240,360))
character_key = character_info.put()
I can see a binary input in gae admin data viewer, but not sure exactly how it works to call it. Then, I passed the characters object into the PageHandler and called a for loop to get each avatar.
{% for character in characters %}
#{{another html page is render here}}
{% endfor %}
tried these, but None of them works.
<img src="/images?img_id={{character.key()}}"></img>
<img src="/images/header.jpg"></img>
<img src="/avatar?avatar_id={{character.key()}}"></img>
So my questions are:
-
How do you determine “/images”(this is the folder?) or “img_id” are the right syntax to use?
-
I don’t see any image uploaded to my localhost, is that correct?
-
Calling an image directly from a folder like
<img src="/images/header.jpg"></img>doesn’t work…(in php it’s works….)
Thanks in advance, any help will be appreciated!
Alright, I figured out what I did wrong was I didn’t add an image handler.
So
This solves my problem.