Django模板标签插入或替换URL参数 [英] Django template tag to insert or replace URL parameter
问题描述
给了/ 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 = / code>。
这从头开始并不难,但由于这似乎是一个很常见的任务,所以我会期待一个标签这是内置的。不过,在阅读 docs 和谷歌搜索后,我不能似乎找到任何人的公开这样的标签。
由于我没有使用这些工具,我会只要参考你:
- django-url-tools 具有 url_params 似乎做你想做的模板标签
- django-more-template-tags-and-filters 有一些帮助器标签用于操纵网址和参数
我已经个人使用 jsurl 库在javascript中进行这种网址操作。
希望有帮助。
Is anyone aware of a Django template tag that takes the current path and query string and inserts or replaces a query string value?
e.g. given a request to /some/custom/path?q=how+now+brown+cow&page=3&filter=person
The call {% urlparam 'page' 4 %}
would generate /some/custom/path?q=how+now+brown+cow&page=4&filter=person
.
This wouldn't be too difficult to write from scratch, but as this seems like a very common task, I would expect a tag like this to be built-in. However, after reading through the docs and googling, I can't seem to find anyone's who's publicized such a tag.
Since I haven't used these tools by my own, I'll just refer you:
- django-url-tools has url_params template tag that seems to do what you want
- django-more-template-tags-and-filters has some helper tags for manipulating urls and parameters
FYI, I've personally used jsurl library for this kind of url manipulations in javascript.
Hope that helps.
这篇关于Django模板标签插入或替换URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!