2013-05-20 19 views
1

我在Google App Engine上使用Python制作邮件应用程序。GAE:如何在1个网页中合并BlobstoreUploadHandler和RequestHandler

我想在'正常'网页(发布到RequestHandler)中启用附件上传(发布到BlobstoreUploadHandler)。

如果用户填写了“正常”表格的一部分,如何在用户上传他(她)的附件后保留这些值(然后在提交帖子之前用javascript复制所有字段)?

+0

为什么不把所有的表单控件放在要发布到服务器的同一表单中? – Marc

+0

@Marc上传必须发布到BlobstoreUploadHandler的派生类,而表单的其余部分必须发布到RequestHandler的派生类。因此他们不能是同一个html

的一部分。 – rimvanvliet

+0

上传:'',其余部分为:''; upload_url由GAE生成。 – rimvanvliet

回答

2

你可以写,从两个类派生的请求处理程序:

class YourRequestHandler(BlobstoreUploadHandler, RequestHandler): 
    pass 

我也webapp2的的RequestHandlers尝试这样做,它的工作原理。 PS:为了防止孤立的斑点因为用户上传了比应用程序期望的更多的文件(这很容易发生,因为您无法控制用户的浏览器),我建议您按照以下几行编写您的文章处理程序:

def post(self): 
    uploads = self.get_uploads() 
    try: 
     pass # Put your application-specific code here. 
     # As soon as you have stored a blob key in the database (using a transaction), 
     # remove the corresponding upload from the uploads array. 
    finally: 
     keys = [upload.key() for upload in uploads] 
     blobstore.delete_multi(keys) 
+0

Tnx!从未使用过多重继承......它解决了我的问题。 – rimvanvliet

相关问题