这似乎相当微不足道,但只需要一些最佳实践指导。
构建一个 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 中出现这个我在这里遗漏了一些明显的东西吗?