2024-07-01 08:06:44 发布
网友
我有一个谷歌应用引擎的小问题,我想从数据存储中检索图像,我的功能是100%工作,如果我在代码中输入键,另一方面,如果我得到一个参数,它会给我BadKeyError
这是表格
{% for image in image.all %} <li>{{ image.title }} </li> <img src='getImage?key={{image.key}}' height="100" />
映射到
我创造了一些和你想要的相似的东西。。希望这有帮助
图像.py
import os from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app class Profile(db.Model): image=db.BlobProperty() class disp_image(webapp.RequestHandler): def get(self): key = self.request.get('key') image = Profile.get(key) self.response.headers['Content-Type'] = "image/png" return self.response.out.write(image.image) class MainPage(webapp.RequestHandler): def get(self): image = self.request.get('image') pro=Profile() if image: pro.image = db.Blob(image) import logging logging.info('persisted') pro.put() prof=Profile().all() return self.response.out.write(template.render('view.html',{'prof':prof})) def post(self): return MainPage.get(self) application = webapp.WSGIApplication([ ('/', MainPage), ('/disp', disp_image) ], debug=True) def main(): run_wsgi_app(application) if __name__ == '__main__': main()
视图.html
应用程序yaml
application: sample-app version: 1 runtime: python api_version: 1 handlers: - url: /.* script: image.py
网址
>>> req.host 'localhost:80' >>> req.host_url 'http://localhost' >>> req.application_url 'http://localhost/blog' >>> req.path_url 'http://localhost/blog/article' >>> req.url 'http://localhost/blog/article?id=1' >>> req.path '/blog/article' >>> req.path_qs '/blog/article?id=1' >>> req.query_string 'id=1'
我创造了一些和你想要的相似的东西。。希望这有帮助
图像.py
视图.html
^{pr2}$应用程序yaml
网址
相关问题 更多 >
编程相关推荐