This is a followup to an issue raised off topic in the thread "Generic
routes for API functions"
http://groups.google.com/group/pylons-discuss/browse_thread/thread/34fe166e0e7228c0
.
I said there that I didn't like that a 404 is raised if routes match
on path but not on HTTP method. I have since found a solution though,
and it's simple enough:
from pylons.controllers.util import abort
def method_condition(method):
# A condition function capable of generating status codes
def check_method(environ, result):
if environ and 'REQUEST_METHOD' in environ and \
environ['REQUEST_METHOD'] not in method:
abort(405)
else:
return True
return check_method
Use with
conditions={'function': method_condition(method)}
on your route. I have a helper that generates either this form or the
simpler
conditions={'method': method}
form depending on the presence of a status code, but I didn't want to
obscure the solution unecessarily.
Enjoy,
Mike
[email protected]
http://positiveincline.com
http://twitter.com/asplake
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.