您正在将图像源指向未定义的错误
img路线。
正确的链接应指向
/image这样:
<img src="http://www.kaotop.com/skin/sinaskin/image/nopic.gif"></img>
我已经通过更正测试了您的代码,并且效果很好:
from google.appengine.ext import dbfrom google.appengine.api import usersfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_appimport loggingclass HomePage(db.Model): thumbnail = db.BlobProperty() firm_name = db.StringProperty()class ImageUpload(webapp.RequestHandler): def get(self): self.response.out.write(""" <form action="/imagesave" enctype="multipart/form-data" method="post"> <div><label>firm name:</label> <input type="text" name="firm_name" size=40></div> <div><input type="file" name="img" /></div> <div><input type="submit" value="Upload image"></div> </form> """)class ImageSave(webapp.RequestHandler): def post(self): homepage = HomePage() thumbnail = self.request.get("img") firm_name = self.request.get("firm_name") homepage.thumbnail = db.Blob(thumbnail) homepage.firm_name = firm_name homepage.put() self.redirect("/imageupload")class ImageResize(webapp.RequestHandler): def post(self): q = HomepageImage.all() q.filter("firm_name", "mta") qTable = q.get() if qTable: qTable.thumbnail = db.Blob(images.resize(self.request.get("img"), 32, 32)) db.put(qTable) else: self.response.out.write("""firm not found""") self.redirect("/imageupload")class DisplayImage(webapp.RequestHandler): def get(self): query = HomePage.all() query.filter("firm_name", "mta") result = query.get() self.response.out.write("""firm name: %s""" % result.firm_name) self.response.out.write("""<img src="http://www.kaotop.com/skin/sinaskin/image/nopic.gif"></img>""" % result.key())class Image(webapp.RequestHandler): def get(self): img_id = self.request.get("img_id") logging.info("""**************************img_id: %s**************************""" % img_id) homepage = db.get(self.request.get("img_id")) if homepage.thumbnail: self.response.headers['Content-Type'] = "image/jpg" self.response.out.write(homepage.thumbnail) else: self.response.out.write("no image")application = webapp.WSGIApplication([("/imageresize",ImageResize),("/imageupload", ImageUpload),("/displayimage", DisplayImage),("/imagesave", ImageSave),("/image", Image),], debug=True)def main(): run_wsgi_app(application)if __name__ == "__main__": main()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)