MCPcopy
hub / github.com/encode/django-rest-framework / replace_query_param

Function replace_query_param

rest_framework/utils/urls.py:6–15  ·  view source on GitHub ↗

Given a URL and a key/val pair, set or replace an item in the query parameters of the URL, and return the new URL.

(url, key, val)

Source from the content-addressed store, hash-verified

4
5
6def replace_query_param(url, key, val):
7 """
8 Given a URL and a key/val pair, set or replace an item in the query
9 parameters of the URL, and return the new URL.
10 """
11 (scheme, netloc, path, query, fragment) = parse.urlsplit(force_str(url))
12 query_dict = parse.parse_qs(query, keep_blank_values=True)
13 query_dict[force_str(key)] = [force_str(val)]
14 query = parse.urlencode(sorted(query_dict.items()), doseq=True)
15 return parse.urlunsplit((scheme, netloc, path, query, fragment))
16
17
18def remove_query_param(url, key):

Callers 13

test_invalid_unicodeMethod · 0.90
reverseMethod · 0.90
get_next_linkMethod · 0.90
get_previous_linkMethod · 0.90
page_number_to_urlMethod · 0.90
get_next_linkMethod · 0.90
get_previous_linkMethod · 0.90
page_number_to_urlMethod · 0.90
encode_cursorMethod · 0.90

Calls

no outgoing calls

Tested by 3

test_invalid_unicodeMethod · 0.72