Simplified django.urls.reverse() a bit.

This commit is contained in:
Sergey Fedoseev 2019-06-12 07:39:39 +05:00 committed by Mariusz Felisiak
parent b616f65855
commit 6fa71872ae
1 changed files with 2 additions and 6 deletions

View File

@ -36,10 +36,7 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
if not isinstance(viewname, str): if not isinstance(viewname, str):
view = viewname view = viewname
else: else:
parts = viewname.split(':') *path, view = viewname.split(':')
parts.reverse()
view = parts[0]
path = parts[1:]
if current_app: if current_app:
current_path = current_app.split(':') current_path = current_app.split(':')
@ -50,8 +47,7 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None):
resolved_path = [] resolved_path = []
ns_pattern = '' ns_pattern = ''
ns_converters = {} ns_converters = {}
while path: for ns in path:
ns = path.pop()
current_ns = current_path.pop() if current_path else None current_ns = current_path.pop() if current_path else None
# Lookup the name to see if it could be an app identifier. # Lookup the name to see if it could be an app identifier.
try: try: