Python Django: Accessing Google App Engine URL - Post then

I have something like this:

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 how, after processing the posted data, can I display the same information as the get (self) function?

0


a source to share


5 answers


Redirection, as others have shown, has some advantage, but it is a bit of a "heavy" approach. Alternatively, consider refactoring the rendering part into a separate helper method def _Render(self):

and just completing the methods get

and post

calling self.Render()

.



+3


a source


Call self.redirect (url) to redirect the user to the same page via GET. This way they won't accidentally resubmit the form if they hit refresh.



+1


a source


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

      

I am using the above django shortcut from shared views where you can specify a post save redirect get in your case. There are some more examples in this snippet. BTW, I assumed you are using django (helper or patch) with an application engine based on the title of the question. If you're using a patch for an application, check out the views.py view in the sample application myapp. The add_person handler does what you are looking for.

0


a source


This is generally not a good idea as it will cause confusion. You should really do what you want and then redirect them to the get method.

0


a source


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

Django generic views are only accessible with app-engine-patch. The assistant does not support them. You can see the app-engine-patch example project to learn more about Django on App Engine: http://code.google.com/p/app-engine-patch/

0


a source







All Articles