Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • 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.

    stunnel dev_http
    

    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
    

    So now you can connect to http://localhost:8001 and https://localhost:8002 to test your application using https.

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - Testing HTTPS with Django's Development Server