TimLeung
TimLeung

Reputation: 3479

Python Django: Handling URL with Google App Engine - Post then Get

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?

Upvotes: 0

Views: 1672

Answers (5)

Alex Martelli
Alex Martelli

Reputation: 881705

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().

Upvotes: 3

Nick Johnson
Nick Johnson

Reputation: 101149

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.

Upvotes: 1

Waldemar Kornewald
Waldemar Kornewald

Reputation:

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/

Upvotes: 0

Surya
Surya

Reputation: 4972

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.

Upvotes: 0

Dustin
Dustin

Reputation: 90980

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.

Upvotes: 0

Related Questions