Decorators

respite.decorators.before(method_name)

Run the given method prior to the decorated view.

If you return anything besides None from the given method, its return values will replace the arguments of the decorated view.

If you return an instance of HttpResponse from the given method, Respite will return it immediately without delegating the request to the decorated view.

Example usage:

class ArticleViews(Views):

    @before('_load')
    def show(self, request, article):
        return self._render(
            request = request,
            template = 'show',
            context = {
                'article': article
            }
        )

    def _load(self, request, id):
        try:
            return request, Article.objects.get(id=id)
        except Article.DoesNotExist:
            return self._error(request, 404, message='The article could not be found.')
Parameters:method – A string describing a class method.
respite.decorators.override_supported_formats(formats)

Override the views class’ supported formats for the decorated function.

Arguments: formats – A list of strings describing formats, e.g. ['html', 'json'].

Previous topic

Respite

Next topic

Routing

This Page