Skip to content

Instantly share code, notes, and snippets.

@jeongtae
Created May 14, 2020 03:33
Show Gist options
  • Save jeongtae/b2a5a15b046ec3b73b24a3f99645bd88 to your computer and use it in GitHub Desktop.
Save jeongtae/b2a5a15b046ec3b73b24a3f99645bd88 to your computer and use it in GitHub Desktop.
definition of build_url_with_query function for Python Django
from django.utils.encoding import escape_uri_path
def build_url_with_query(origin_url: str, **params) -> str:
"""
Builds an URL with query string for the GET requesting method.
"""
mapped_params = map(
lambda k: f"{escape_uri_path(k)}={escape_uri_path(params[k])}", params
)
result_url = origin_url.rstrip("?") + "?" + "&".join(mapped_params)
return result_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment