views:

1040

answers:

5

I have something like this set up:

class CategoryPage (webapp.RequestHandler):
def get(self):
    ** DO SOMETHING HERE **
def post(self):
 ** DO SOMETHING HERE **
 ** RENDER THE SAME AS get(self)

The question is, after I process the posted data, how would I be able to display the same information as the get(self) function?

A: 
create_object(request, form_class=FormClass,
        post_save_redirect=reverse('-get-url-handler-',
                                   kwargs=dict(key='%(key)s')))

I use the above django shortcut from generic views where you can specify post save redirect , get in your case . There are few more examples in this snippet . Btw, I assumed that you are using django ( helper or patch) with app engine , based on the title of the question. If you are using app engine patch , check out the views.py in "myapp" app sample add_person handler does what you are looking for.

Surya
I do have the django help with app engine. Would it be possible if you explain the above code a bit ? Thanks.
TimLeung
A: 

That's generally not a good idea as it'll cause confusion. You should really do whatever it is you want to do and then redirect them to the get method.

Dustin
A: 

Actually, your code isn't Django, but webapp (Google's mini-"framework"). Please read the Django documentation: http://docs.djangoproject.com/

Django's generic views are only available with app-engine-patch. The helper doesn't support them. You could take a look at the app-engine-patch sample project to learn more about Django on App Engine: http://code.google.com/p/app-engine-patch/

+1  A: 

Call self.redirect(url) to redirect the user back to the same page over GET. That way, they won't accidentally re-submit the form if they hit refresh.

Nick Johnson
+3  A: 

A redirect, as others suggest, does have some advantage, but it's something of a "heavy" approach. As an alternative, consider refactoring the rendering part into a separate auxiliary method def _Render(self): and just ending both the get and post methods with a call to self.Render().

Alex Martelli