How to run a local Django development server over HTTPS with a trusted self-signed SSL certificate
Aug 10, 2021 · Updated: Jun 24, 2026 · by Tim Kamanin
Generating a self-signed SSL certificate for local Django development has always been a hassle for me — until the day I discovered mkcert, a zero-config tool that creates locally trusted development certificates your browser won't complain about.
In this tutorial, I'll walk you through my process. You'll learn how to create a local SSL certificate for your Django project and run the development server with HTTPS enabled.
Let's get started.
Step 1 - Generating a local SSL certificate
-
First, let's install
mkcerton your machine. If you are running on macOS, you can use Homebrew package manager to do this. Run the following command in your terminal:brew install mkcertIf you're running on Linux or Windows, please refer to the installation instructions in the package repo (https://github.com/FiloSottile/mkcert#windows).
-
Next, let's make your operating system trust the local certificates we're about to generate. To do this, you need to install a local certificate authority (CA) in the system trust store. Run the following command:
mkcert -install -
Next, you need to generate a certificate for the localhost domain.
In the terminal, go to the root of your Django project. Then run the following command to generate a certificate for
localhostand127.0.0.1:mkcert -cert-file cert.pem -key-file key.pem localhost 127.0.0.1If you plan to run your local server under a domain other than localhost, replace localhost with the domain of your choice.
If everything went right, you should see the following result:
mkcert command output The certificate is at "cert.pem" and the key at "key.pem"
As a result, we have generated a local SSL certificate that will work with any localhost development server running on any port.
FYI: You can reuse this certificate with any local project that runs on localhost. The certificate has nothing to do with Django or Python.
Step 2 - Configuring Django server to work with HTTPS
The default Django manage.py runserver command doesn't support SSL; therefore, we need to use the
alternative manage.py runserver_plus command, which is part of the excellent Django Extensions package.
-
Run the following command to install Django Extensions along with the Werkzeug server:
pip install django-extensions WerkzeugThe
runserver_pluscommand requires the Werkzeug server, which is better known in the world of the Python framework Flask. -
Next, open the
settings.pyfile in your code editor and adddjango_extensionsto theINSTALLED_APPSlist:settings.py INSTALLED_APPS = [ # other apps "django_extensions", ] -
Finally, start the local development server in HTTPS mode by running the command:
python manage.py runserver_plus --cert-file cert.pem --key-file key.pem
And that's it — you should now see the local development server running at the default https://localhost:8000 address.
Hey, if you've found this useful, please share the post to help other folks find it: