Force SSL on your Django site.
Project description
Do you want to force HTTPs across your Django site? You’re in the right place!
Meta
Author: Randall Degges
Email: r@rdegges.com
Site: http://www.rdegges.com
Status: maintained, active
Purpose
Enabling SSL on your Django site should be easy, easy as in one-line-of-code easy. That’s why I wrote django-sslify!
The goal of this project is to make it easy for people to force HTTPS on every page of their Django site, API, web app, or whatever you’re building. Securing your site shouldn’t be hard.
Installation
To install django-sslify, simply run:
$ pip install django-sslify
This will install the latest version of the library automatically.
If you’re using Heroku, you should add django-sslify>=0.2 to your requirements.txt file:
$ echo 'django-sslify>=0.2.0' >> requirements.txt
Once you’ve done this, the next time you push your code to Heroku this library will be installed for you automatically.
Usage
To use this library, and force SSL across your Django site, all you need to do is modify your settings.py file, and prepend sslify.middleware.SSLifyMiddleware to your MIDDLEWARE_CLASSES setting:
# settings.py
MIDDLEWARE_CLASSES = (
'sslify.middleware.SSLifyMiddleware',
# ...
)
If you’re using Heroku, you should also add the following settings to your Django settings file:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
This ensures that Django will be able to detect a secure connection properly.
Using a Custom SSL Port
If your site is running on a non-standard SSL port, you can change django-sslify’s default redirection behavior by setting a special variable in your settings.py file:
SSLIFY_PORT = 999
Disabling SSLify
If you’d like to disable SSLify in certain environments (for local development, or running unit tests), the best way to do it is to modify your settings file and add the following:
SSLIFY_DISABLE = True
Notes
This code was initially taken from this StackOverflow thread.
This code has been adopted over the years to work on Heroku, and non-Heroku platforms.
If you’re using Heroku, and have no idea how to setup SSL, read this great article which talks about using the new SSL endpoint addon (which totally rocks!).
Contributing
This project is only possible due to the amazing contributors who work on it!
If you’d like to improve this library, please send me a pull request! I’m happy to review and merge pull requests.
The standard contribution workflow should look something like this:
Fork this project on Github.
Make some changes in the master branch (this project is simple, so no need to complicate things).
Send a pull request when ready.
Also, if you’re making changes, please write tests for your changes – this project has a full test suite you can easily modify / test.
To run the test suite, you can use the following commands:
$ cd django-sslify
$ python setup.py develop
$ python manage.py test sslify
Change Log
All library changes, in descending order.
Version 0.2.4
Released on November 23, 2014.
Adding the ability to specify a custom SSL port.
Totally revamping docs.
Changing project logo / mascot thingy ^^
Adding new tests for custom SSL ports.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-sslify-0.2.4.tar.gz
.
File metadata
- Download URL: django-sslify-0.2.4.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d874e61543ab842142b109b971484692f8204fe7188bbf5cf0fd54b5374c363 |
|
MD5 | 58bad08c8b34b5a1af3196d52489fffe |
|
BLAKE2b-256 | 2eba45db1446410919f5323e41520f199d52429228c6eecd831ba2dddb88234e |