user2294401
user2294401

Reputation: 387

How can i pass the request object in inclusion tag in django

I am overrding the admin ChangeList class and i am adding my own function there which requires request object like this

class MyChangeList(ChangeList):

    def sample(self, request):
        test = request.session["myvar"]
        return test

in the inclusion tag i need to use like this

@register.inclusion_tag("admin/change_list_results.html")
def my_result_list(cl):
    """
    Displays the headers and data list together
    """
    myvar = cl.sample()
    num_sorted_fields = 0

How can i do that?

Upvotes: 2

Views: 865

Answers (1)

Eduard Iskandarov
Eduard Iskandarov

Reputation: 862

Pass takes_context=True to tag decorator.

@register.inclusion_tag("admin/change_list_results.html", takes_context=True)
def my_result_list(context, cl):
    """
    Displays the headers and data list together
    """
    myvar = cl.sample(context['request'])
    num_sorted_fields = 0

Documentation

Upvotes: 3

Related Questions