Matthew H
Matthew H

Reputation: 5879

Pylons - Handling GET and POST requests

What's the best way to handle form POST data in my Pylons app? I've tried:

Upvotes: 1

Views: 1092

Answers (1)

Manoj Govindan
Manoj Govindan

Reputation: 74705

Having it all in one method, and detecting if the form has been posted via a check on request.method. This works okay, but it seems clumsy to have if request.method == 'post': ... else: ...

I am not sure why you describe this as clumsy. Switching on request method is a valid idiom in the web app world across languages. For e.g. you'll find Django views having a single view that handles requests differently based on request.method. Similarly in Java, Servlets have doPost() and doGet() methods to provide different behavior for GET and POST requests.

Update

I'd just rather have them separated into different methods, if possible. Many other web frameworks do this

Nothing wrong with this approach either. I was merely pointing out that having the same method handle them is equally valid.

Upvotes: 2

Related Questions