【问题标题】:How do I pass a template variable as part of a string parameter to a template tag?如何将模板变量作为字符串参数的一部分传递给模板标签?
【发布时间】:2012-07-13 13:05:45
【问题描述】:

我将此链接用于我的模板。我的目的是将用户带到分页的下一页......好吧,页面:

<a href="{% query_string 'page=page.next_page_number' 'page' %}">Next</a>

问题是 page.next_page_number 没有被评估为下一个页码。

模板标签函数 query_string 应该删除然后将字符串参数附加到 url。

我看到这张票正是我的问题所在:

Add querystring helper methods to Page class

我的目标是解决这个问题:

Manipulate URL query strings using context variables using a template tag

谁能帮帮我?

【问题讨论】:

    标签: django url query-string django-pagination templatetag


    【解决方案1】:

    我不是 100% 确定它会有所帮助,但在您的示例中,您将文字传递给模板标签,传递变量,去掉引号:

    <a href="{% query_string page=page.next_page_number page %}">Next</a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-14
      • 2015-06-22
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多