How do I pass a template variable as part of a string parameter to a template tag?
-
20-06-2021 - |
문제
I use this link for my template. My intention is to bring the user to the next page of a paginated.. well, page:
<a href="{% query_string 'page=page.next_page_number' 'page' %}">Next</a>
The problem is page.next_page_number is not evaluated as the next page number.
The template tag function query_string is supposed to remove then append the string argument to the url.
I saw this ticket to be exactly what my problem is:
Add querystring helper methods to Page class
I was aiming to make this the solution:
Manipulate URL query strings using context variables using a template tag
Can anyone help me please?
해결책
I am not 100% sure it will help, but in your example you pass a literal to template tag, to pass a variable, drop quotation marks:
<a href="{% query_string page=page.next_page_number page %}">Next</a>
제휴하지 않습니다 StackOverflow