Skip to content

Instantly share code, notes, and snippets.

@agriffis
Created February 28, 2013 13:41
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 agriffis/5056791 to your computer and use it in GitHub Desktop.
Save agriffis/5056791 to your computer and use it in GitHub Desktop.
Force django admin to SSL
def walk_url_tree(urls):
"""
Generator to walk a tree consisting of RegexURLPattern (with callback)
and RegexURLResolver (with nested url_patterns).
"""
for u in urls:
if hasattr(u, 'url_patterns'):
for u2 in walk_url_tree(u.url_patterns):
yield u2
else:
yield u
# Enable the admin
from django.contrib import admin
admin.autodiscover()
# Force admin to SSL: Resolve the admin.site.urls property then walk the
# tree, wrapping the callbacks with ssl_required.
ssl_admin_urls = admin.site.urls
for u in walk_url_tree(ssl_admin_urls[0]):
u._callback = ssl_required(u.callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment