Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3450782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:05:00+00:00 2026-05-18T09:05:00+00:00

I am trying to understand the documentation Using the Images Python API and I

  • 0

I am trying to understand the documentation Using the Images Python API and I am confused about how to get the key and display the avatar.

Documentation says that the Image handler will serve the image off the /img path.

I am confused about what this Image handler does. I comment below how understand it; please correct. Thanks:

class Image (webapp.RequestHandler):
    def get(self):
        #get the key of the image "img_id" from datastore
        #what is the value of "img_id"? Where does it come from?
        #how does the app engine know to get what key for which image?
        greeting = db.get(self.request.get("img_id"))
        #what is greeting.avatar?
        #is it img_id.avatar ?
        #I assume "avatar" refers to the "avatar" property in the model
        if greeting.avatar:
            self.response.headers['Content-Type'] = "image/png"
            #does this display the avatar?
            #I thought the img tag displayed the avatar
            self.response.out.write(greeting.avatar)
       else:
          self.error(404)

Many thanks for your help.


UPDATE (re: answer by Gabi Purcaru)

Thanks again for the clear answer. I have a query that displays the user comments like this:

    for result in results:
        self.response.out.write("<li>")
        self.response.out.write("<b>%s</b> %s " % (result.userName, result.userLatestComment))
        self.response.out.write("</li>")
    self.response.out.write("</ol></body></html>")

so, I copy the line with the image tag from the MainPage handler

self.response.out.write("<div><img src='img?img_id=%s'></img>" % greeting.key())

and change

greeting.key()

to

result.key()

I assume that, this should now display the avatar next to the user comment:

    for result in results:
        self.response.out.write("<li>")
        self.response.out.write("<b>%s</b> %s " % (result.userName, result.userLatestComment))
        self.response.out.write("<div><img src='img?img_id=%s'></img>" % result.key())
        self.response.out.write("</li>")
    self.response.out.write("</ol></body></html>")

but still not clear why result.key() is the key of the image I want to display?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:05:01+00:00Added an answer on May 18, 2026 at 9:05 am
    1. "img_id" comes from the GET part of the url (something like “www.example.com/img?img_id=12312“). The engine assigns a new unique key for every model in the database.

    2. greeting.avatar is the avatar property of the model with the key img_id. So, in some sense, you can think of it like img_id.avatar, although technically it is not correct.

    3. that does not display the avatar, it is just returning the avatar. Let’s take a usual image for example for you to understand better. When you write <img src="some_link" />, the browser will look for "some_link", and include that image. The browser will then read the image from the filesystem, and return it to the browser. What your handler does is changing the backend part, so that the webserver will return the image from the datastore (specifically that avatar property) instead of a regular file. The browser — and the user — will see it as a regular image.

    EDIT:
    result.key() is the unique identifier that the database automatically gave your model. You need to “tell it” to the image handler you just wrote, for it to know which particular model avatar you need. You do that by setting the img_id GET variable for the url (which you just did).

    I am not sure if you understand the whole .key() thing. Let me explain that:

    Any database needs to identify one record from another (model in our case). This is why they will automatically assign a new, and most importantly unique identifier (key in our case) to each and every record inserted in the database. You will have to provide the model’s key for your handler to return the avatar of that model.

    Let’s take a real-world example: you are an individual amongst many. The way that your country uniquely identifies you is by some kind of SSN (Social Security Number). In my country it is a 13-digits code (e.g. 1024582485008). If I want to get my driver licence, I will have to provide my name, but that is not enough — I’m not the only Gabi Purcaru in my country. I will also have to provide my SSN, which will tell exactly who I am. If we make an analogy, you have to provide the model’s “SSN” (i.e. key) to the handler, so that it will know which model to get from the database and return it’s avatar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to download multiple images concurrently using Python over the internet, and I've
I'm learning Squeryl and trying to understand the 'using' syntax but can't find documentation
I am trying to understand how CoffeeScript variables are scoped. According to the documentation:
I'm trying to understand how ID3 tags work, so, after reading some documentation, I
Trying to understand the Deezer API. When I visit: http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access I end up at
I'm working through the Erlang documentation, trying to understand the basics of setting up
I am trying to understand the Simulink (continuous) transfer function. In the documentation for
I'm having a weird situation that I'm trying to understand. This piece of code
I'm trying to get tipfy working on Google App Engine (GAE). I'm using Windows
I'm trying to understand how to get my iPhone application working with RegexKitLite ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.