mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 19:43:59 +03:00
21 lines
594 B
Python
21 lines
594 B
Python
|
"""
|
||
|
Provide reverse functions that return fully qualified URLs
|
||
|
"""
|
||
|
from django.core.urlresolvers import reverse as django_reverse
|
||
|
from django.utils.functional import lazy
|
||
|
|
||
|
|
||
|
def reverse(viewname, *args, **kwargs):
|
||
|
"""
|
||
|
Same as `django.core.urlresolvers.reverse`, but optionally takes a request
|
||
|
and returns a fully qualified URL, using the request to get the base URL.
|
||
|
"""
|
||
|
request = kwargs.pop('request', None)
|
||
|
url = django_reverse(viewname, *args, **kwargs)
|
||
|
if request:
|
||
|
return request.build_absolute_uri(url)
|
||
|
return url
|
||
|
|
||
|
|
||
|
reverse_lazy = lazy(reverse, str)
|