我有一个关于提供/渲染保存在 blobstore 中的图像的问题
我得到一个 404 错误它似乎找到了 url?? http://clockinapple.appspot.com/serve/AMIfv97XybVYJy5Jk1e7WCSfCc-IO7zBtlVaC8ef8-Im /etc/
代码与示例基本相同 - 非常感谢任何帮助
这是我的处理程序代码:
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = unicode(str(urllib.unquote(resource)))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
class GetBlobstoreUrl(BaseHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload/')
self.response.out.write(upload_url)
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
user_info = blobstore.BlobInfo.all().get().filename
text = user_info
head, sep, tail = text.partition('.')
user_info = head
photo = clockin.UserPhoto(blob_key=blob_info.key(), employee=user_info)
photo.put()
class GetLogs(BaseHandler):
def get(self):
logs = clockin.UserPhoto.all()
params = {'logs': logs}
return self.render_template('logs.html', **params)
这是我的模型代码:
class UserPhoto(db.Model):
employee = db.StringProperty(db.Key)
blob_key = blobstore.BlobReferenceProperty()
create_timestamp = db.DateTimeProperty(auto_now_add=True)
update_timestamp = db.DateTimeProperty(auto_now=True)
我的路线:
RedirectRoute('/serve/([^/]+)?', ServeHandler, name='serve_handler', strict_slash=True),
RedirectRoute('/logs/', GetLogs, name='get_logs', strict_slash=True),
RedirectRoute('/get_blobstore_url/', GetBlobstoreUrl, name='get_blobstore_url', strict_slash=True),
我如何为 html 提供服务:(我们是实例)
<td><img src='/serve/{{us.blob_key.key()}}'></img></td>