mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Moved relative URL handling added in refs #21177 to a better place.
Thanks apollo13: "reverse() shouldn't know about absolute/relative paths."
This commit is contained in:
parent
be6d1f39e8
commit
8251438cb8
@ -383,10 +383,6 @@ class RegexURLResolver(LocaleRegexProvider):
|
||||
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:
|
||||
|
@ -10,6 +10,7 @@ from django.db.models.base import ModelBase
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user