Created
November 22, 2012 11:45
-
-
Save jokull/4130738 to your computer and use it in GitHub Desktop.
Much better URL reversal in Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding=utf-8 | |
from django.core.urlresolvers import reverse | |
def burl_context(request): | |
def burl(name, *args, **kwargs): | |
external = kwargs.pop('_external') | |
path = reverse(name, args=args, kwargs=kwargs) | |
if external: | |
protocol = 'https' if request.is_secure() else 'http' | |
return '%s://%s%s' % (protocol, request.get_host(), path) | |
return path | |
return { | |
'burl': burl, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course you need Coffin (Jinja2).