View Decorators
- awl.decorators.json_post_required(*decorator_args)
View decorator that enforces that the method was called using POST and contains a field containing a JSON dictionary. This method should only be used to wrap views and assumes the first argument of the method being wrapped is a
request
object.@json_post_required('data', 'json_data') def some_view(request): username = request.json_data['username']
- Parameters:
field – The name of the POST field that contains a JSON dictionary
request_name – [optional] Name of the parameter on the request to put the deserialized JSON data. If not given the field name is used
- awl.decorators.post_required(method_or_options=[])
View decorator that enforces that the method was called using POST. This decorator can be called with or without parameters. As it is expected to wrap a view, the first argument of the method being wrapped is expected to be a
request
object.@post_required def some_view(request): pass @post_required(['firstname', 'lastname']) def some_view(request): pass
The optional parameter contains a single list which specifies the names of the expected fields in the POST dictionary. The list is not exclusive, you can pass in fields that are not checked by the decorator.
- Parameters:
options – List of the names of expected POST keys.