When I try the straight code from the "Using Images" (http://
code.google.com/appengine/docs/images/usingimages.html) that writes
the html directly from the main.py file, my image display works.  When
I use templates that are separate from the main.py file, the images
don't display even though they are in the datastore and show up when I
view the source of the html page.

Please look at my code and tell me if I am missing a call or if the
MainPage class needs a reference for the image...

Template Page:
<img src='/image?img_id={{ greeting.key }}'></img>

What it is outputting:
<img src='/image?img_id=agtqZW50ZXN0bGl2ZXIOCxIIR3JlZXRpbmcYBgw'></
img>

The main.py is below.  I am getting the same results both in dev and
on my testing spot on GAE. Thanks in advance for your help!

Jen

********

import cgi
import datetime
import os
import logging

from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import images
from google.appengine.ext.webapp import template

logging.getLogger().setLevel(logging.DEBUG)


class Greeting(db.Model):
  author = db.UserProperty()
  fullname = db.StringProperty()
  know = db.StringProperty()
  avatar = db.BlobProperty()
  year = db.StringProperty()
  title = db.StringProperty()
  content = db.TextProperty()
  date = db.DateTimeProperty(auto_now_add=True)

class MainPage(webapp.RequestHandler):
  def get(self):
    greetings_query = Greeting.all().order('-date')
    greetings = greetings_query.fetch(10)

    if users.get_current_user():
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
      path = os.path.join(os.path.dirname(__file__), 'post.html')
    else:
      url = users.create_login_url(self.request.uri)
      url_linktext = 'Login'
      path = os.path.join(os.path.dirname(__file__), 'index.html')

    template_values = {
      'greetings': greetings,
      'url': url,
      'url_linktext': url_linktext,
      }

    self.response.out.write(template.render(path, template_values))

class Image (webapp.RequestHandler):
  def get(self):
    greeting = db.get(self.request.get("img_id"))
    if greeting.avatar:
      self.response.headers['Content-Type'] = "image/png"
      self.response.out.write(greeting.avatar)
    else:
      self.response.out.write("No image")

class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()

    if users.get_current_user():
      greeting.author = users.get_current_user()
    greeting.fullname = self.request.get('fullname')
    greeting.know = self.request.get('know')
    avatar = images.resize(self.request.get('img'), 32, 32)
    greeting.avatar = db.Blob(avatar)
    greeting.year = self.request.get('year')
    greeting.title = self.request.get('title')
    greeting.content = self.request.get('content')
    greeting.put()
    self.redirect('/')


application = webapp.WSGIApplication(
                                      [('/', MainPage),
                                       ('/img', Image),
                                       ('/sign', Guestbook)],
                                       debug=True)

def main():
  run_wsgi_app(application)

if __name__ == '__main__':
  main()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to