Skip to content

Instantly share code, notes, and snippets.

@bootandy
Created December 11, 2012 12:34
Show Gist options
  • Select an option

  • Save bootandy/4258249 to your computer and use it in GitHub Desktop.

Select an option

Save bootandy/4258249 to your computer and use it in GitHub Desktop.
add a parameter to the url. Overwrite param if it is already there
def _merge_new_params_with_referring_url(url, param_name=None, param_value=None):
if not url:
return '/'
if not param_name or not param_value:
return url
scheme, network, path, query, fragment = urlparse.urlsplit(url)
query_map = urlparse.parse_qs(query)
query_map[param_name] = str(param_value)
new_query = urllib.urlencode(query_map, doseq=True)
return urlparse.urlunsplit((scheme, network, path, new_query, fragment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment