diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 2ee4b457f..838eebc35 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -254,7 +254,7 @@ class SimpleRouter(BaseRouter): # so a slash in the beginning will (A) cause Django to give # warnings and (B) generate URLS that will require using '//'. if not prefix and regex[:2] == '^/': - regex = f'^{regex[2:]}' + regex = '^' + regex[2:] initkwargs = route.initkwargs.copy() initkwargs.update({ diff --git a/rest_framework/urlpatterns.py b/rest_framework/urlpatterns.py index e4b4aedcb..1ed5f89f8 100644 --- a/rest_framework/urlpatterns.py +++ b/rest_framework/urlpatterns.py @@ -11,7 +11,7 @@ def _get_format_path_converter(suffix_kwarg, allowed): else: allowed_cases = "|".join(allowed) allowed_pattern = f'(?:{allowed_cases})' - suffix_pattern = fr"\.{allowed_pattern}/?" + suffix_pattern = r"\.%s/?" % allowed_pattern else: suffix_pattern = r"\.[a-z0-9]+/?" @@ -102,9 +102,9 @@ def format_suffix_patterns(urlpatterns, suffix_required=False, allowed=None): else: allowed_cases = "|".join(allowed) allowed_pattern = f'({allowed_cases})' - suffix_pattern = fr'\.(?P<{suffix_kwarg}>{allowed_pattern})/?$' + suffix_pattern = r'\.(?P<%s>%s)/?$' % (suffix_kwarg, allowed_pattern) else: - suffix_pattern = fr'\.(?P<{suffix_kwarg}>[a-z0-9]+)/?$' + suffix_pattern = r'\.(?P<%s>[a-z0-9]+)/?$' % suffix_kwarg converter_name, suffix_converter = _get_format_path_converter(suffix_kwarg, allowed) register_converter(suffix_converter, converter_name) diff --git a/rest_framework/utils/html.py b/rest_framework/utils/html.py index d10dbcf8e..c7ede7803 100644 --- a/rest_framework/utils/html.py +++ b/rest_framework/utils/html.py @@ -83,7 +83,7 @@ def parse_html_dict(dictionary, prefix=''): } """ ret = MultiValueDict() - regex = re.compile(fr'^{re.escape(prefix)}\.(.+)$') + regex = re.compile(r'^%s\.(.+)$' % re.escape(prefix)) for field in dictionary: match = regex.match(field) if not match: