Running Django Development Server with HTTPS using Ngrok
Learn how to serve your Django application over HTTPS during development using ngrok and django-sslserver.

Introduction
When developing web applications with Django, it's often necessary to test features that require HTTPS, such as payment gateways or OAuth authentication. By default, Django's development server runs over HTTP, making it challenging to test these features locally. In this post, we'll explore how to serve your Django application over HTTPS during development using ngrok and django-sslserver.
Step 1: Generate Self-Signed Certificates
To serve your Django application over HTTPS, you'll need a certificate and private key. You can generate self-signed certificates using the mkcert tool. First, install mkcert using Homebrew by running:
brew install mkcertThen, install the root CA in your system's trust store:
mkcert -installGenerate a certificate and private key for localhost:
mkcert -cert-file cert.pem -key-file key.pem localhost 127.0.0.1Step 2: Install django-sslserver
To serve your Django application over HTTPS, you'll need to install the django-sslserver package. Run the following command:
pip install django-sslserverAdd 'sslserver' to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
...
'sslserver',
]Step 3: Run Django Development Server with HTTPS
You can now run your Django development server with HTTPS using the following command:
python manage.py runsslserverBy default, runsslserver will use the certificate and private key generated earlier.
Step 4: Expose Your Local Server to the Internet using Ngrok
To expose your local server to the internet, you'll need to use ngrok. Run the following command:
ngrok http https://localhost:8000Ngrok will create a tunnel to your local server, allowing you to access it from anywhere.
Conclusion
In this post, we demonstrated how to serve your Django application over HTTPS during development using ngrok and django-sslserver. By following these steps, you can test features that require HTTPS locally, making your development workflow more efficient.
Tags
Comments (0)
Leave a Comment
No comments yet. Be the first to share your thoughts!