Swan Mougnoz Swan Mougnoz - 8 months ago 49
Python Question

Unpack dictionary as template tag arguments

Is there a way to use a dictionary as named arguments in a template tag in Django?

Assuming I have a dictionary like :

my_dict = {
'param1': 'value1',
'param2': 'value2'

I know that can do for example :


But can I do something like :

{% url 'my_app.viewname' **my_dict %}

The url tag is actually what I'm trying to use here, maybe is there an other way to achieve this?


Django template language is not Python, so no, there's no argument unpacking etc. You can eventually write you own custom url tag taking a dict as argument, but that's about it.