def query_string(context, key, value):
"""
For adding/replacing a key=value pair to the GET string for a URL.
eg, if we're viewing ?p=3 and we do {% url_replace order 'taken' %}
then this returns "p=3&order=taken"
And, if we're viewing ?p=3&order=uploaded and we do the same thing, we get
the same result (ie, the existing "order=uploaded" is replaced).
Expects the request object in context to do the above; otherwise it will
just return a query string with the supplied key=value pair.
"""
try:
request = context['request']
args = request.GET.copy()
except KeyError:
args = QueryDict('').copy()
args[key] = value
return args.urlencode()
评论列表
文章目录