commit
d8a974bb4f
|
@ -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
|
||||
|
||||
|
|
|
@ -30,11 +30,17 @@ class Router:
|
|||
@sanic.route('/my/url/<my_parameter>', methods=['GET', 'POST', ...])
|
||||
def my_route(request, my_parameter):
|
||||
do stuff...
|
||||
or
|
||||
@sanic.route('/my/url/<my_paramter>: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 <parameter>. 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 <parameter>. 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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -5,6 +5,7 @@ class HTTPMethodView:
|
|||
""" Simple class based implementation of view for the sanic.
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user