First, I'm extremely new to coding and self-taught, so models / views / DOM fall on deaf ears (but willing to learn!)
So I saved images into a database as blobs (BlobProperty), now trying to serve them.
Relevant Code: (I took out a ton for ease of reading)
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 %}
Its seems that imageit isn't actually being called or the path is wrong or... I don't know. So many attempts and fails.
Resources I've tried but fail to understand:
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
This seemed to be dang close, but I can't figure out how to implement. Need a "for dummies" translation.
How to load Blobproperty image in Google App Engine?