Published in


Django Development Server with HTTPS

Sometimes you can’t avoid using HTTPS right starting from development (such as for developing Facebook canvas applications). You can setup Apache on your local machine and go through a bunch of trouble setting up your domain and setting up the certificate etc but there’s an easy way of using Django’s python manage.py runserver to work with HTTPS.

This can be done with stunnel that lets the Facebook server and stunnel on your machine communicate in SSL and stunnel turns around to communicate with Python in HTTP. First install stunnel. For instance in Mac OS X:

brew install stunnel

Then you need to create a settings file for stunnel to execute. You can create a text file anywhere. For instance, you can create dev_https and input:

stunnel creates a fake certificate. By default on Mac, it's at /usr/local/etc/stunnel/stunnel.pem. It'll bring up a warning on your browser saying that your webpage can be fake but Facebook operations still work right. Since stunnel has to listen on one port and Python's development server cannot run on the same server, you must use different ports for accept (incoming) and connect (internal). Once you have your dev_https file or whatever you called it, run
sudo stunnel dev_httpsto start the tunnelling. Then start your Python server.HTTPS=1 python manage.py runserver variable HTTPS must be set to 1 for it to return secure responses and since we previously set the internal port to 8002, we listen on 8002 from all incoming IPs. Then, your IP:8001 can accept HTTPS connections without changing your webserver and you can continue running another instance of HTTP Python server on a different port.Source




Collection of tech tips and learnings

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Django Plausible Proxy

Convert Django website to PWA

The curious case of Authentication with django rest framework

Understanding Templates in Django | part 1

Django Templates