Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved relative URL handling added in refs #21177 to a better place.

Thanks apollo13: "reverse() shouldn't know about absolute/relative paths."
  • Loading branch information...
commit 8251438cb8c1d47779e9fc33cfa84dad9851a774 1 parent be6d1f3
Tim Graham timgraham authored
Showing with 6 additions and 4 deletions.
  1. +0 −4 django/core/urlresolvers.py
  2. +6 −0 django/shortcuts.py
4 django/core/urlresolvers.py
View
@@ -383,10 +383,6 @@ def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
text_args = [force_text(v) for v in args]
text_kwargs = dict((k, force_text(v)) for (k, v) in kwargs.items())
- if isinstance(lookup_view, six.string_types):
- # Handle relative URLs
- if any(lookup_view.startswith(path) for path in ('./', '../')):
- return lookup_view
try:
lookup_view = get_callable(lookup_view, True)
except (ImportError, AttributeError) as e:
6 django/shortcuts.py
View
@@ -10,6 +10,7 @@
from django.db.models.manager import Manager
from django.db.models.query import QuerySet
from django.core import urlresolvers
+from django.utils import six
def render_to_response(*args, **kwargs):
@@ -147,6 +148,11 @@ def resolve_url(to, *args, **kwargs):
if hasattr(to, 'get_absolute_url'):
return to.get_absolute_url()
+ if isinstance(to, six.string_types):
+ # Handle relative URLs
+ if any(to.startswith(path) for path in ('./', '../')):
+ return to
+
# Next try a reverse URL resolution.
try:
return urlresolvers.reverse(to, args=args, kwargs=kwargs)
Please sign in to comment.
Something went wrong with that request. Please try again.