简体   繁体   中英

How to pass multiple parameters to named groups url

I don't know how to pass multiple parameters through template url reverse lookup

<a href="{% url 'planner_by_location' {'pk':location.pk,'year':date_single[:3],'month':date_single[-6:5], 'day':date_single[-11:9]}  %}">test</a>

to match this url pattern:

r'^something/date/(?P<pk>\d+)/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$'

Get error:

Could not parse the remainder: '{"pk":location.pk,' from '{"pk":location.pk,'

Somebody has a clue?

The Django template language is not python. You cannot pass dictionaries as arguments, or use square brackets for slicing variables.

The example in the docs shows how to pass named arguments to the url tag.

{% url 'some-url-name' arg1=v1 arg2=v2 %}

You can use the slice filter as well.

year=date_single|slice:":3"

https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#url https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#slice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM