Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Force SSL on your Django admin site.

Project Description

django-sslify-admin

Force SSL on your Django admin site

Install

To install django-sslify-admin, simply run pip install django-sslify-admin and you’ll get the latest version installed automatically.

Usage

Modify your Django settings.py file, and prepend sslifyadmin.middleware.SSLifyAdminMiddleware to your MIDDLEWARE_CLASSES setting:

MIDDLEWARE_CLASSES = (
    'sslifyadmin.middleware.SSLifyAdminMiddleware',
    # ...
)

NOTE: Make sure sslify.middleware.SSLifyMiddleware is the first middleware class listed, as this will ensure that if a user makes an unsecure request (over HTTP), they will be redirected to HTTPs before any actual processing happens. If you plan to use `i18n_patterns <https://docs.djangoproject.com/en/dev/topics/i18n/translation/#django.conf.urls.i18n.i18n_patterns>`__ on admin urls, this middleware needs to be appended AFTER `django.middleware.locale.LocaleMiddleware <https://docs.djangoproject.com/en/dev/ref/middleware/#django.middleware.locale.LocaleMiddleware>`__!

Custom admin url?

If you are using a custom admin url, you have to set SSLIFY_ADMIN_NAMESPACE in your settings.py:

# SSLIFY_ADMIN_NAMESPACE = "admin" # default
SSLIFY_ADMIN_NAMESPACE = "myadminurl" # custom

Enabling/Disabling

By default, the admin is sslfying if settings.DEBUG is False, but for some reason (ie. local, test suite) you may want remove debugging and not trigger the sslify. You have to set SSLIFY_ADMIN_DISABLE in your settings.py:

SSLIFY_ADMIN_DISABLE = True

Behind a Proxy? (Heroku)

If your Django app is behind a proxy (like Heroku), though, the proxy may be “swallowing” the fact that a request is HTTPS, using a non-HTTPS connection between the proxy and Django.

In this situation, you’ll want to configure the proxy (Heroku already does that for you) to set a custom HTTP header that tells Django whether the request came in via HTTPS, and you’ll want to set SECURE_PROXY_SSL_HEADER so that Django knows what header to look for, like this:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Notes

This code was taken and modified from this StackOverflow thread. This Project is also influenced by Randall Degges django-sslify, use this, if you want to secure your whole site, and not only the admin interface of Django.

If you like this project please consider giving me a gittip, thanks! :)

Tests

$ git clone https://github.com/return1/django-sslify-admin.git
$ cd django-sslify-admin
$ python setup.py develop
...
$ python setup.py test
Creating test database for alias 'default'...
..
----------------------------------------------------------------------
Ran 2 tests in 0.003s

OK
Destroying test database for alias 'default'...
Release History

Release History

This version
History Node

0.5.0

History Node

0.4

History Node

0.3

History Node

0.2

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-sslify-admin-0.5.0.tar.gz (4.2 kB) Copy SHA256 Checksum SHA256 Source Jul 3, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting