Skip to content

Instantly share code, notes, and snippets.

@jokull
Created November 22, 2012 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokull/4130738 to your computer and use it in GitHub Desktop.
Save jokull/4130738 to your computer and use it in GitHub Desktop.
Much better URL reversal in Django
# 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,
}
@jokull
Copy link
Author

jokull commented Nov 22, 2012

Of course you need Coffin (Jinja2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment