Created
May 14, 2020 03:33
-
-
Save jeongtae/b2a5a15b046ec3b73b24a3f99645bd88 to your computer and use it in GitHub Desktop.
definition of build_url_with_query function for Python Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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