python - Django 1.6 templates Is it possible to wrap the {% url %} so it can take ** arguements? How? -
the django's built-in tag url
tag works like:
{% url 'path.to.some_view' arg1=v1 arg2=v2 %}
i want write super_url
tag works like:
kwargs={'arg1':v1,'arg2':v2,} {% super_url 'path.to.some_view' **kwargs %}
or take dictionary arguments:
{% super_url 'path.to.some_view' kwargs %}
is possible? how?
you can't pass url
tag dictionary in template , should try avoid performing sort of login in template anyway (unpacking dictionaries etc.).
instead, write own custom template tag using the reverse
function. (untested):
from django.core.urlresolvers import reverse @register.simple_tag(takes_context=true) def kwargy_url(context, view_str, kwargs): ... return reverse(view_str, kwargs=kwargs) # {% kwargy_url 'myapp.views.myview' kwarg_var %}
Comments
Post a Comment