Mike,
I do something like this in my controllers:
import pylons.decorators.rest as rest
from app.lib.errors import MethodNotAllowedError
class QuestionController(BaseController):
@rest.dispatch_on(GET='get_questions', POST='add_questions')
def questions(self, id):
raise MethodNotAllowedError(method=request.method, allowed=["GET",
"POST"])
MethodNotAllowedError is an exception class I wrote which serializes to a 405
error.
- Shailesh
Mike Burrows (asplake) wrote:
> Apologies - I was too hasty. I was fooled into thinking that 405's
> were being generated but all I was seeing was the logging of
> exceptions. A full solution needs a change somewhere in the
> middleware stack I guess. We can pretend I never posted but please
> reply if you would like to me to pursue this further!
>
> On Dec 15, 9:19 am, "Mike Burrows (asplake)" <[email protected]>
> wrote:
>> I should add that you use this only on the last route for any given
>> path, or you'll never reach the later ones!
>>
>> Mike
>>
>> On Dec 15, 9:13 am, "Mike Burrows (asplake)" <[email protected]>
>> wrote:
>>
>>> 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/34...
>>> .
>>> 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.comhttp://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.
>
>
--
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.