0

我有一个关于提供/渲染保存在 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>
4

1 回答 1

1

我直接查询了blobstore并且图像正确显示我希望这可以帮助某人我的处理程序:

class PicDownload(BaseHandler):
    def get(self):
        emps = clockin.Employee.all().fetch(100)
        ekey = self.request.GET.get("select1")
        ekey = str(ekey)
        afile = [] 
        blob_info = blobstore.BlobInfo.all().filter('filename =', ekey+'.jpg').order('-  creation').fetch(20)
        for a in blob_info:
        afile.append(get_serving_url(a))

        form = 'get_pics.html'

        params = {'blob_info': blob_info,
                  'afile': afile,
                  }

        return self.render_template(form, **params)

在 HTML 方面:

<select id="select1" name='select1' onchange='this.form.submit()'>
{% for e in emps %}
    <option value={{e.key()}} ><href a=/pic_download/{{e.key()}}>{{e.username}}
    </href>    
    </option>
{% endfor %}
</select>
于 2012-07-27T17:19:32.977 回答