Package: django-sslify
Do you want to force HTTPs across your Django site? You’re in the right place!MetaAuthor: Randall DeggesEmail:r@rdegges.comSite:http://www.rdegges.comStatus: maintained, activePurposeEnabling SSL on your Django site should be easy, easy as inone-line-of-code
easy.  That’s why I wrotedjango-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.InstallationTo installdjango-sslify, simply run:$pipinstalldjango-sslifyThis will install the latest version of the library automatically.If you’re usingHeroku, you should adddjango-sslify>=0.2to yourrequirements.txtfile:$echo'django-sslify>=0.2.0'>>requirements.txtOnce you’ve done this, the next time you push your code to Heroku this library
will be installed for you automatically.UsageTo use this library, and force SSL across your Django site, all you need to do
is modify yoursettings.pyfile, and prependsslify.middleware.SSLifyMiddlewareto yourMIDDLEWARE_CLASSESsetting:# settings.pyMIDDLEWARE_CLASSES=('sslify.middleware.SSLifyMiddleware',# ...)NoteMake suresslify.middleware.SSLifyMiddlewareis the first middleware
class listed, as this will ensure that if a user makes an insecure request
(over HTTP), they will be redirected to HTTPs before any actual
processing happens.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 PortIf your site is running on a non-standard SSL port, you can changedjango-sslify’s default redirection behavior by setting a special variable
in yoursettings.pyfile:SSLIFY_PORT=999Disabling SSLifyIf 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=TrueYou can also disable SSLify for certain requests only (useful for exposing
HTTP-only web hook URLs, etc) by adding a callable with a single request
parameter to theSSLIFY_DISABLE_FOR_REQUESTlist.  ReturningTruefrom
your callable will disable SSL redirects.SSLIFY_DISABLE_FOR_REQUEST=[lambdarequest:request.get_full_path().startswith('/no_ssl_please')]NotesThis code was initially taken fromthis 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, readthis great articlewhich talks about using the new SSL endpoint addon (which totally rocks!).NGINX + Infinite RedirectIf you’re running your Django app behind an Nginx load balancer, and are seeing
infinite redirects, the solution is to add the following line:proxy_set_header X-Forwarded-Proto $scheme;To yournginx.conffile, inside of the relevantlocationblocks.  ThisStack Overflow threadmight also be useful.ContributingThis 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:$cddjango-sslify$pythonsetup.pydevelop$pythonmanage.pytestsslifyChange LogAll library changes, in descending order.Version 0.2.5Released December 28, 2014.Adding in newSSLIFY_DISABLE_FOR_REQUESTsetting which allows a user to
specify functions that can choose to reject SSL – this is useful for
situations where you might want to force SSL site-wide EXCEPT in a few
circumstances (webhooks that don’t support SSL, for instance).Version 0.2.4Released 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.