首先,我非常新的编码和自学成才的,所以模型/聋子的耳朵(但愿意学习!)AppEngine上动态加载BlobProperty图像
所以我保存的图像到的意见/ DOM秋天数据库作为blob(BlobProperty),现在试图为它们服务。
相关代码:(我拿出一吨为了便于阅读)
class Mentors(db.Model):
id = db.StringProperty()
mentor_id = db.StringProperty()
name = db.StringProperty()
img_file = db.BlobProperty()
class ImageHandler (webapp2.RequestHandler):
def get(self):
mentor_id=self.request.get('mentor_id')
mentor = db.GqlQuery("SELECT * FROM Mentors WHERE mentor_id = :1 LIMIT 1", mentor_id)
if mentor.img_file:
self.response.headers['Content-Type'] = "image/jpg"
self.response.out.write(mentor.img_file)
else:
self.error(404)
application = webapp2.WSGIApplication([
routes.DomainRoute('medhack.prebacked.com', medhack_pages),
webapp2.Route(r'/', handler=HomepageHandler, name='home-main'),
webapp2.Route(r'/imageit', handler=ImageHandler, name='image-handler')
],
debug=True)
class MedHackHandler(webapp2.RequestHandler):
def get(self, url="/"):
# ... bunch of code to serve template etc.
mentors_events = db.GqlQuery("SELECT * FROM Mentors_Events WHERE event_id = :1 ORDER BY mentor_type DESC, mentor_id ASC", current_event_id)
mentors = mentors_events
HTML:
{% for m in mentors %}
#here 'mentors' refers to mentors_event query, and 'mentor' refers to the mentors table above.
<img src="imageit?mentor_id={{m.mentor.mentor_id}}" alt="{{m.mentor.name}} headshot"/>
{% endfor %}
它似乎imageit实际上没有被调用或路径错误,或者......我不知道。如此多的尝试和失败。
资源我做过尝试,但不明白:
https://developers.google.com/appengine/articles/python/serving_dynamic_images
show images on the templates of django using google app engine
https://sites.google.com/site/usfcomputerscience/storing-and-serving-images
这似乎是宕接近,但我无法弄清楚如何实施。需要一个“傻瓜”翻译。 How to load Blobproperty image in Google App Engine?
好的,谢谢。固定,但仍然没有骰子。在代码中更新它。 – MrDunham
选择这个作为答案,因为我没有提供足够的信息(子域路由错误),并且您发现了另一个错误。谢谢丹尼尔。 – MrDunham