0
我試圖做 接收兩個參數, 密鑰,和「實體中的列位置信息」 從通用圖像顯示類,並返回並顯示從blob提供的指定圖像。 如果你知道我做錯了什麼,請給我一個提示。Google App Engine(Python):如何使用URL參數在實體中指定一個列?
我有像下面這樣的數據存儲「item」,
Key | image_index | image1 | image2 | image3 |
,我請求圖像中包含的URL,
http://stackoverwlow.com/image/ {鍵}/{image_N}
我做了主像下面URL處理器,
def main():
application = webapp.WSGIApplication(
[('/', MainPage),
('/image/([^/]+)/([^/]+)', imageDisplay),
], debug=True)
wsgiref.handlers.CGIHandler().run(application)
和
我製作的imageDisplay類如下,
from google.appengine.ext import db
from google.appengine.ext import webapp
class imageDisplay(webapp.RequestHandler):
def get(self, _key, _size):
image = db.get(_key)
self.response.headers['Content-Type'] = 'image/jpg'
self.response.out.write(image._size)
但是,如果我嘗試這個代碼,它將返回下列錯誤,
全局名稱「IMAGE_SIZE」沒有定義
如果我指定應顯示的圖像中的實體,有用。 因此,數據在那裏。
self.response.out.write(image.image3)
我的問題是,如何從獲得的實體「圖像」指定「_size」?
預先感謝您。
與問候
Hello Nick, self.response.out.write(getattr(image,size)) 按預期工作!非常感謝你。 我想弄清楚如何使用db.ListProperty(db.Blob)。但是,不知道如何應用它。在我的每個條目中,有幾個圖像存儲爲blob。所以,不知道如何選擇應該使用哪一個圖像。,, – soabe 2011-01-14 04:45:37