Skip to content

Instantly share code, notes, and snippets.

@jokull
Created November 22, 2012 11:45
Show Gist options
  • Select an option

  • Save jokull/4130738 to your computer and use it in GitHub Desktop.

Select an option

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

jokull commented Nov 22, 2012

Copy link
Copy Markdown
Author

Of course you need Coffin (Jinja2).

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