There is very little difference in my get and post methods. One way to do this would be to put the common logic in another function and call that in both the get and post methods. But before I do that I wanted to know If I can actually have one function handle both, that'll be really neat.
Asked
Active
Viewed 516 times
0
-
you can make the post call get or vice versa. just do self.get() or self.post() – marcadian Jul 22 '14 at 23:23
2 Answers
3
You can also use a BaseHandler for your handlers. You can put common methods for sessions, login and templates in the BaseHandler.
See this example for sessions or this blog post about webapp2 and templates.
2
This is a good description of when to use GET vs POST. You can use either, of course, but there are situations where you'd want to use one vs the other. You can use the same methods to process them from within the same class if you wanted to like this:
class MyHandler(webapp2.RequestHandler):
def function_to_handle_requests(self):
# code goes here
def get(self):
self.function_to_handle_requests
def post(self):
self.function_to_handle_requests

Community
- 1
- 1

user3058197
- 1,052
- 1
- 9
- 21