Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should have an <code>&lt;img&gt;</code> tag in your template that has a <code>src</code> attribute that contains a URL that is served by your application and delivers the data for the image. For example, let's say that you store images in a model called Image:</p> <pre><code>class Image(db.Model): filename = db.StringProperty() # The name of the uploaded image mime_type = db.StringProperty() # The mime type. content = db.BlobProperty() # The bytes of the image def load(id): # Load an entity from the database using the id. Left as an # exercise... def link_id_for(self): "Returns an id that uniquely identifies the image" return self.key().id() </code></pre> <p>In the controller/request handler code that renders the page that contains the image, you would pass the id that is returned by <code>link_id_for</code> to the template, and the template would have your image tag, something like this:</p> <pre><code>&lt;img src="/images/show/{{image_id}}"&gt; </code></pre> <p>You would have a request handler that handles requests to <code>/images/show/id</code>. You would use <em>id</em> to get the Image entity out of the datastore and the send it back in the response, something like this:</p> <pre><code>found_image = Image.load(id) response.headers['Content-Type'] = str(found_image.mime_type) response.out.write(found_image.content) </code></pre> <p>Obviously, you'd have to adapt the particulars of the code to your current application structure and conventions, but that's the heart of it: use an <code>img</code> tag with a <code>src</code> that points at your application; your application includes a request handler the delivers the bytes and a <code>Content-Type</code> header.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload