Reputation: 1438
I'm trying to deploy the following python code named image-getter.py in GAE:
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext import os
from google.appengine.ext.webapp.util import run_wsgi_app
#the addimage endpoint
class AddImage(webapp.RequestHandler):
def post(self):
image = self.request.get('image')
i = Image()
i.picture = db.Blob(image)
i.put()
self.response.out.write('done');
#the Image object:
class Image(db.Model):
picture = db.BlobProperty();
#to get the image : /getimage?key=sdfsadfsf...
class GetImage(webapp.RequestHandler):
def get(self):
images_query = Image.get(self.request.get('key'))
if (images_query and images_query.picture):
self.response.headers['Content-Type'] = "image/jpeg"
self.response.out.write(images_query.picture)
#to draw the images out to the main page:
class MainPage(webapp.RequestHandler):
def get(self):
images = db.Query(Image)
keys = [];
for image in images:
keys.append(str(image.key()))
template_values = {'images' : keys}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
def main():
app = webapp.WSGIApplication(
[('/', MainPage),
], debug=True)
The above code uses the os library, but I thought you weren't allowed to us it in GAE.
My app.yaml file looks like:
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
script: image-getter.app
libraries:
The html, index.html file looks like:
<div>
{% for i in images %}
<img src="/getimage?key={{i}}" />
{% endfor %}
</div>
I can't seem to get the app to run, I get "Error: Server Error," which isn't awfully helpful.
Thank!
Upvotes: 0
Views: 49
Reputation: 2618
There is no image-getter.app in your image-getter.py. Also there is no routing in your image-getter.py check example here https://developers.google.com/appengine/docs/python/gettingstartedpython27/helloworld
You need to add something like
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
When you post code, please include the import statements, your code seems invalid because it does not import the db module.
Upvotes: 2