简体   繁体   English

什么是最好的Google App Engine blobstore工作流程?

[英]What is the best Google App Engine blobstore workflow?

What is the best workflow for uploading file to the blobstore while saving information about the blob and other fields to a model record? 在将blob和其他字段的信息保存到模型记录的同时,将文件上载到blobstore的最佳工作流程是什么?

For example, should I submit the form to the blobstore upload url (blobstore.create_upload_url), clean the form, redirect if errors and save and redirect if not? 例如,我应该将表单提交到blobstore上传URL(blobstore.create_upload_url),清理表单,如果错误则重定向并保存并重定向,如果没有?

What is the best way to pass the errors back? 将错误传回的最佳方法是什么? GET variables? GET变量? I tried using models to the save the form errors and redirecting based on the form error model instance, but that was messy. 我尝试使用模型来保存表单错误并根据表单错误模型实例重定向,但这很麻烦。 Any ideas? 有任何想法吗?

The solution I've come up with for this is not the prettiest but it gets the job done. 我为此提出的解决方案并不是最漂亮的,但它可以完成工作。 On the upload view (view that is specified in the create_upload_url function) I'm passing the post variables to the same form class from the first page. 在上传视图(在create_upload_url函数中指定的视图)我将post变量从第一页传递到相同的表单类。 If the form is valid I'm saving the variables along with the BlobInfo.key to the model. 如果表单有效,我将变量与BlobInfo.key一起保存到模型中。 If it is not a valid form I'm saving the errors in memcache and redirecting back to the first page with the variable of error that triggers the view to retrieve the errors from memcache and add them to the form instance. 如果它不是一个有效的表单我将保存错误在memcache中并重定向回第一页,其中包含错误变量,触发视图从memcache中检索错误并将它们添加到表单实例。

So again here's the steps. 所以这里是步骤。

  1. Create form view 创建表单视图
  2. Check POST variables with the same form from the first view 使用第一个视图中的相同表单检查POST变量
  3. If the form is valid save it along with the BlobInfo.key, if not save errors to memcache with a small lifespan and redirect to first view with the memcache key in the url 如果表单有效,请将其与BlobInfo.key一起保存,如果没有将错误保存到具有较小生命周期的memcache,并使用url中的memcache键重定向到第一个视图
  4. Retrieve the form errors from memcache and add them to the new form instance 从memcache中检索表单错误并将它们添加到新表单实例
  5. Resubmit the form with errors fixed and save 重新提交已修复错误的表单并保存

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM