I'm working on a Google App Engine project that collects stories submitted by users.
This is how I handle submission errors in the post method of my Request Handler:
# get the title and content using self.request.get()
errors = []
if not title:
errors.append("Please enter a title.")
if not content:
errors.append("Please enter a story.")
if not errors:
# create the story, save it to the database
# redirect to the story's page
else:
# pass the title and/or content to a template
# pass the error message(s) to a template
# the same template that displays the submission form is used here
The problem: since my form sends posts to example.com/createstory.do -- if there are errors I end up redisplaying the form page at that address.
What I want to happen: redirect the user back the page where they submitted the form: example.com/Share, while at the same time displaying the error messages and redisplaying the submitted form data.
What's the easiest way to do this?
I know I could just have /Share handle both get and post requests, but I'm looking for a solution that I can use even when doing that wouldn't be an option.