Testing HTTPS with Django's Development Server
Django's development server doesn't normally support HTTPS so it's hard to test applications with HTTPS without deploying the application to a real web server that supports HTTPS. The secret is to use two development server instances, one for http and one for https, and to use a tool called stunnel to can create an ssl tunnel to the development server to support HTTPS.
First we need to set up stunnel using the documentation .
After it's installed you can create a pem for stunnel.
openssl req -new -days 365 -nodes -out newreq.pem -keyout /etc/stunnel/stunnel.pem
After that we create a settings file (which I saved to a file called dev_https). The "accept" setting is the port of the HTTPS connection. The "connect" is the port of the development server instance we are using for https.
pid = [https] accept=8002 connect=8003
After that we start the stunnel daemon.
Now we start the Django development server instance we are going to use for https. The HTTPS=on environment variable allows request.is_secure() to return True properly.
HTTPS=on python manage.py runserver 8003
Then we start the http server.
python manage.py runserver 8000
blog comments powered by Disqus