Implement a custom reverse that builds absolute URLs with a request object

This commit is contained in:
Daniel Izquierdo 2012-02-20 18:46:47 +09:00
parent a29ca6c2d0
commit 13110a386c

View File

@ -1,6 +1,6 @@
from django.utils.encoding import smart_unicode from django.utils.encoding import smart_unicode
from django.utils.xmlutils import SimplerXMLGenerator from django.utils.xmlutils import SimplerXMLGenerator
from django.core.urlresolvers import resolve, reverse from django.core.urlresolvers import resolve, reverse as django_reverse
from django.conf import settings from django.conf import settings
from djangorestframework.compat import StringIO from djangorestframework.compat import StringIO
@ -174,5 +174,6 @@ class XMLRenderer():
def dict2xml(input): def dict2xml(input):
return XMLRenderer().dict2xml(input) return XMLRenderer().dict2xml(input)
def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None):
raise NotImplementedError def reverse(viewname, request, *args, **kwargs):
return request.build_absolute_uri(django_reverse(viewname, *args, **kwargs))