Decorators

Below is the list of decorators available in this project.

ajax_login_required

This decorator works like the built-in Django login_required but it handles AJAX requests differently. For AJAX requests, this decorator passes back custom headers to tell the client to redirect to the login page. These headers are caught by a ajaxComplete listener contained within jquery.dj.hilbert.js.

This is based on answers from the Stackoverflow question “How to manage a redirect request after a JQuery Ajax call?”.

@ajax_login_required
def authenticated_view(request):
    return HttpResponse()

ajax_only

The ajax_only decorator ensures that all requests made to a particular view are made as AJAX requests. Non-AJAX requests will recieve a 400 (Bad Request) response. This is based on snippet 771.

@ajax_only
def ajax_view(request):
    return HttpResponse()

anonymous_required

New in version 0.2.

This decorator is the opposite of login_required . It ensures that users attempting to view this page are not authenticated. By default this will redirect autheticated users to the server root ‘/’ or you can specify another url as either an absolute path or as as named url pattern.

@anonymous_required(url='/hilbert/test/simple/')
def anonymous_only_view(request):
    return HttpResponse()

secure

New in version 0.2.

This decorator is similar to SSLRedirectMiddleware but works independently. Decorating a view with secure will force this view to be accessed only over SSL.

@secure
def secure_view(request):
    return HttpResponse()

Project Versions

Table Of Contents

Previous topic

Motivation

Next topic

Finders

This Page