Django模板标签插入或替换URL参数 [英] Django template tag to insert or replace URL parameter

查看:85
本文介绍了Django模板标签插入或替换URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道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 = / code>。



这从头开始并不难,但由于这似乎是一个很常见的任务,所以我会期待一个标签这是内置的。不过,在阅读 docs 和谷歌搜索后,我不能似乎找到任何人的公开这样的标签。

解决方案

由于我没有使用这些工具,我会只要参考你:





我已经个人使用 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:

FYI, I've personally used jsurl library for this kind of url manipulations in javascript.

Hope that helps.

这篇关于Django模板标签插入或替换URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆