有人知道 Django 模板标签可以获取当前路径和查询字符串并插入或替换查询字符串值吗?
例如向 /some/custom/path?q=how+now+brown+cow&page=3&filter=person 发出请求
电话{% urlparam 'page' 4 %}
会产生/some/custom/path?q=how+now+brown+cow&page=4&filter=person
.
从头开始编写这并不太困难,但由于这似乎是一项非常常见的任务,因此我希望内置这样的标签。然而,读完之后docs https://docs.djangoproject.com/en/1.4/ref/templates/builtins/谷歌搜索,我似乎找不到任何人公开这样的标签。
由于我自己没有使用过这些工具,所以我只是向您推荐:
-
django-url-工具 https://pypi.python.org/pypi/django-url-tools has 网址参数 https://bitbucket.org/monwara/django-url-tools#url-params模板标签似乎可以做你想做的事
-
django-more-模板-标签和过滤器 https://github.com/strogonoff/django-more-template-tags-and-filters有一些辅助标签 https://github.com/strogonoff/django-more-template-tags-and-filters/blob/master/more_template_tags/templatetags/more_tags.py用于操作 url 和参数
仅供参考,我个人使用过jsurl https://github.com/Mikhus/jsurljavascript 中用于此类 url 操作的库。
希望有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)