Try to imitate Rails' _method parameter in webapp2

Before default_dispatcher is called, check the _method parameter and rewrite the value of request.method to the corresponding method, so prepare your own dispatcher and set it with the app.router.set_dispatcher method.

def dispatcher(router, request, response):
    method = request.get('_method').upper()
    if method in ['HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE']:
        request.method = method
    return router.default_dispatcher(request, response)
    
app = webapp2.WSGIApplication([
    webapp2.Route('/foo', handler=FooHandler),
], debug=True)
app.router.set_dispatcher(dispatcher)

Recommended Posts

Try to imitate Rails' _method parameter in webapp2
Try implementing extension method in python
Try to calculate Trace in Python
Try to put data in MongoDB
Cython to try in the shortest
Try logging in to qiita with Python
Method to build Python environment in Xcode 6
Try to implement Oni Maitsuji Miserable in python
Try to calculate a statistical problem in Python
3.14 π day, so try to output in Python
How to implement Rails helper-like functionality in Django
To dynamically replace the next method in python
Try to calculate RPN in Python (for beginners)
Try implementing the Monte Carlo method in Python
Try using an object-oriented class in R (R6 method)
Try to make a Python module in C language
[python] Method to darken RGB value in hexadecimal notation
Try to improve your own intro quiz in Python
Try to solve Sudoku in various ways (SAT, CSP)
Try to delete tweets in bulk using Twitter API
Try to put LED in your own PC (slightly)
[Python] Created a method to convert radix in 1 second
Try to decipher the login data stored in Firefox