mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 18:13:57 +03:00
24 lines
764 B
Python
24 lines
764 B
Python
"""
|
|
Provide reverse functions that return fully qualified URLs
|
|
"""
|
|
from django.core.urlresolvers import reverse as django_reverse
|
|
from djangorestframework.compat import reverse_lazy as django_reverse_lazy
|
|
|
|
|
|
def reverse(viewname, request, *args, **kwargs):
|
|
"""
|
|
Do the same as `django.core.urlresolvers.reverse` but using
|
|
*request* to build a fully qualified URL.
|
|
"""
|
|
url = django_reverse(viewname, *args, **kwargs)
|
|
return request.build_absolute_uri(url)
|
|
|
|
|
|
def reverse_lazy(viewname, request, *args, **kwargs):
|
|
"""
|
|
Do the same as `django.core.urlresolvers.reverse_lazy` but using
|
|
*request* to build a fully qualified URL.
|
|
"""
|
|
url = django_reverse_lazy(viewname, *args, **kwargs)
|
|
return request.build_absolute_uri(url)
|