def get(self, key): test = db.get(key) if str(test.kind()).__eq__("RealmKeys"): realm = test if not realm: self.error(404) newupload = UploadRequestKeys() newupload.realm_key = realm newupload.expire_date = datetime.now() + timedelta(hours=1) newupload.put() result = dict(type="image", upload_url=str(self.request.url).replace(key, str(newupload.key()))) json = simplejson.JSONEncoder().encode(result) self.response.headers["Content-Type"] = "application/json" self.response.out.write(json) elif str(test.kind()).__eq__("UploadRequestKeys"): url = self.request.url context = {"url": url, "type": "image"} path = os.path.join(os.path.dirname(__file__), "templates", "upload_form.html") # render the template with the provided context self.response.out.write(template.render(path, context))