diff --git a/sanic/request.py b/sanic/request.py index 8023fd9c..bc7fcabb 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -67,7 +67,7 @@ class Request(dict): try: self.parsed_json = json_loads(self.body) except Exception: - log.exception("failed when parsing body as json") + log.exception("Failed when parsing body as json") return self.parsed_json @@ -89,7 +89,7 @@ class Request(dict): self.parsed_form, self.parsed_files = ( parse_multipart_form(self.body, boundary)) except Exception: - log.exception("failed when parsing form") + log.exception("Failed when parsing form") return self.parsed_form diff --git a/sanic/router.py b/sanic/router.py index 8392dcd8..4cc1f073 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -30,11 +30,17 @@ class Router: @sanic.route('/my/url/', methods=['GET', 'POST', ...]) def my_route(request, my_parameter): do stuff... + or + @sanic.route('/my/url/:type', methods['GET', 'POST', ...]) + def my_route_with_type(request, my_parameter): + do stuff... Parameters will be passed as keyword arguments to the request handling - function provided Parameters can also have a type by appending :type to - the . If no type is provided, a string is expected. A regular - expression can also be passed in as the type + function. Provided parameters can also have a type by appending :type to + the . Given parameter must be able to be type-casted to this. + If no type is provided, a string is expected. A regular expression can + also be passed in as the type. The argument given to the function will + always be a string, independent of the type. """ routes_static = None routes_dynamic = None diff --git a/sanic/utils.py b/sanic/utils.py index 5d896312..88444b3c 100644 --- a/sanic/utils.py +++ b/sanic/utils.py @@ -47,11 +47,11 @@ def sanic_endpoint_test(app, method='get', uri='/', gather_request=True, return request, response except: raise ValueError( - "request and response object expected, got ({})".format( + "Request and response object expected, got ({})".format( results)) else: try: return results[0] except: raise ValueError( - "request object expected, got ({})".format(results)) + "Request object expected, got ({})".format(results)) diff --git a/sanic/views.py b/sanic/views.py index 980a5f74..9387bcf6 100644 --- a/sanic/views.py +++ b/sanic/views.py @@ -3,8 +3,9 @@ from .exceptions import InvalidUsage class HTTPMethodView: """ Simple class based implementation of view for the sanic. - You should implement methods(get, post, put, patch, delete) for the class + You should implement methods (get, post, put, patch, delete) for the class to every HTTP method you want to support. + For example: class DummyView(View): @@ -14,9 +15,11 @@ class HTTPMethodView: def put(self, request, *args, **kwargs): return text('I am put method') etc. - If someone try use not implemented method, there will be 405 response - If you need any url params just mention them in method definition like: + If someone tries to use a non-implemented method, there will be a + 405 response. + + If you need any url params just mention them in method definition: class DummyView(View): def get(self, request, my_param_here, *args, **kwargs):