Created
February 28, 2013 13:41
-
-
Save agriffis/5056791 to your computer and use it in GitHub Desktop.
Force django admin to SSL
This file contains 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
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