Kevin
Kevin

Reputation: 4351

Displaying images form datastore

I am just testing out displaying images on GAE, I have this little .py

import cgi
import wsgiref.handlers
from google.appengine.api import users
from google.appengine.api import images
from google.appengine.ext import db
from google.appengine.ext import webapp

class ImgUpload(db.Model):
  project_name = db.StringProperty()
  project_description = db.StringProperty(multiline=True)
  img_name = db.StringProperty()
  img_img = db.BlobProperty()
  date = db.DateTimeProperty(auto_now_add=True)

class UploadPage(webapp.RequestHandler):
  def get(self):
    self.response.out.write("""<html><body>
          <form action="/upload" enctype="multipart/form-data" method="post">
            <div><label>Project Name</label></div>
            <div><textarea name="title" rows="2" columns "60"></textarea></div>
            <div><label>Despcription:</label></div>
            <div><textarea name="content" rows="3" cols="60"></textarea></div>
            <div><label>Image Name</label></div>
            <div><textarea name="imgname" row="1" cols="60"></textarea></div>
            <div><label>Image</label></div>
            <div><input type="file" name="img"/></div>
            <div><input type="submit" value="Upload" /></div>
          </form>
        </body>
      </html>""")

  def post(self):
    images = ImgUpload()
    project_name = self.request.get('title')
    project_description = self.request.get('content')
    img_img = self.request.get('img')
    img_name = self.request.get('imgname')
    images.img_img = db.Blob(img_img)
    images.project_name = project_name
    images.project_description = project_description
    images.img_name = img_name
    images.put()
    self.redirect('/upload')

class DisplayPage(webapp.RequestHandler):
  def get(self):
    display = db.GqlQuery("SELECT * "
                          "FROM display "
                          "WHERE ANCESTOR IS :1 "
                          "ORDER BY date DESC LIMIT 5"
                          )

    for record in display:
      self.response.out.write('<b>%s</> is the Name' % record.project_name)

def main():
  application = webapp.WSGIApplication(
                                       [('/', UploadPage),
                                        ('/display', DisplayPage)
                                       ],
                                       debug=True)

  wsgiref.handlers.CGIHandler().run(application)

if __name__=="__main__":
  main()

When I run this, I get a KindError: No implementation for kind 'display'. Is this an issue pertaining to lack of a DB key, I know they data is in the store, I can see it in the admin, and I can't see any naming issue (at least off the top of my head, there could be thousands for all that I know). What exactly is causing this error to pop? Thank you in advance for your advice.

Upvotes: 1

Views: 164

Answers (1)

Robert Kluin
Robert Kluin

Reputation: 8292

In your GQL you are selecting from the "display" kind. You don't have a display kind defined, you have a "ImgUpload" kind defined. Using the object interface to query will help you avoid this type of problem.

I also don't see a parameter being passed to the query for it to filter on, so you're going to get another error there.

Upvotes: 1

Related Questions