(template, key=PAGE_LABEL)
return decorator
Return a view dynamically switching template if the request is Ajax.

    Decorate a view that takes a *template* and *extra_context* keyword
    arguments (like generic views).
    The template is switched to *page_template* if request is ajax and
    if *querystring_key* variable passed by the request equals to *key*.
    This allows multiple Ajax paginations in the same page.
    The name of the page template is given as *page_template* in the
    extra context.
Return a view dynamically switching template if the request is Ajax.
Return a view dynamically switching template if the request is Ajax .
def page_template(template, key=PAGE_LABEL):
    """Return a view dynamically switching template if the request is Ajax.

    Decorate a view that takes a *template* and *extra_context* keyword
    arguments (like generic views).
    The template is switched to *page_template* if request is ajax and
    if *querystring_key* variable passed by the request equals to *key*.
    This allows multiple Ajax paginations in the same page.
    The name of the page template is given as *page_template* in the
    extra context.
    """
    def decorator(view):
        @wraps(view)
        def decorated(request, *args, **kwargs):
            # Trust the developer: he wrote ``context.update(extra_context)``
            # in his view.
            extra_context = kwargs.setdefault('extra_context', {})
            extra_context['page_template'] = template
            # Switch the template when the request is Ajax.
            querystring_key = request.REQUEST.get(
                'querystring_key', PAGE_LABEL)
            if request.is_ajax() and querystring_key == key:
                kwargs[TEMPLATE_VARNAME] = template
            return view(request, *args, **kwargs)
        return decorated

    return decorator
def page_template ( template , key = PAGE_LABEL ) : def decorator ( view ) : @ wraps ( view ) def decorated ( request , * args , * * kwargs ) : # Trust the developer: he wrote ``context.update(extra_context)`` # in his view. extra_context = kwargs . setdefault ( 'extra_context' , { } ) extra_context [ 'page_template' ] = template # Switch the template when the request is Ajax. querystring_key = request . REQUEST . get ( 'querystring_key' , PAGE_LABEL ) if request . is_ajax ( ) and querystring_key == key : kwargs [ TEMPLATE_VARNAME ] = template return view ( request , * args , * * kwargs ) return decorated return decorator