【发布时间】:2012-12-27 00:11:42
【问题描述】:
这似乎相当琐碎,但只需要一些最佳实践指导。
构建一个 webapp2 Python 项目(两者都相当新)
我有一个个人资料页面,您可以从中上传新的个人资料图片。
我的个人资料页面相当简单,它有一个带有文件输入的表单,提交给 ProfileImageUpload 处理程序。
class Profile(Handler):
def get(self):
#renders page
和一个图像上传处理程序
class ProfileImageUpload(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('img')
blob_info = upload_files[0]
if self.validate_file(blob_info):
#save the user blob
#redirect to profile page
else:
#redirect to profile page with error
我的映射是
('/user([0-9]+)', Profile),
('/profileupload', ProfileImageUpload),
所以在快乐的情况下,我的 imageUpload 处理程序重定向回个人资料页面,即
/user<userid>
但在错误情况下,我想重定向回来并显示错误,但我无法找到一种方法来执行此操作而不会在 URL 中出现错误,即 /user?error='something'
理想情况下,我不希望在 URL 中出现这种情况,我在这里遗漏了一些明显的东西吗?
【问题讨论】:
-
或不重定向并发送错误页面。在此页面中,您可以发布到.....
标签: python google-app-engine webapp2