2.0 KiB
2.0 KiB
Step 5: Set Up HTTPS with mkcert (Windows)
1. Install mkcert (if not already installed):
choco install mkcert
2. Install local certificate authority:
mkcert -install
3. Create certificates directory:
mkdir certs
mkcert -cert-file certs/localhost+2.pem -key-file certs/localhost+2-key.pem localhost 127.0.0.1 ::1
This creates: • certs/localhost+2.pem (certificate) • certs/localhost+2-key.pem (private key)
4. Install Uvicorn (ASGI server with SSL support):
Ensure you are at the project root and venv is activated:
pip install uvicorn[standard]
5. Update requirements.txt:
pip freeze > requirements.txt
6. Create run.bat script (Windows):
@echo off
uvicorn backend.asgi:application ^
--host 127.0.0.1 --port 8000 ^
--ssl-keyfile ./certs/localhost+2-key.pem ^
--ssl-certfile ./certs/localhost+2.pem
Note: Replace backend with your project name if different.
7. Create VS Code launch configuration (optional):
For debugging in VS Code, create .vscode/launch.json:
mkdir .vscode -Force
@"
{
"version": "0.2.0",
"configurations": [
{
"name": "Django HTTPS (Uvicorn)",
"type": "debugpy",
"request": "launch",
"module": "uvicorn",
"args": [
"backend.asgi:application",
"--host", "0.0.0.0",
"--port", "8000",
"--ssl-keyfile", "./certs/localhost+2-key.pem",
"--ssl-certfile", "./certs/localhost+2.pem",
"--reload"
],
"django": true,
"justMyCode": true,
"python": "`${workspaceFolder}/venv/Scripts/python.exe"
}
]
}
"@ | Out-File -FilePath .vscode/launch.json -Encoding utf8
This allows you to:
- Run and debug Django with F5 in VS Code
- Set breakpoints in your Django code
- Automatic venv activation via the
pythonpath
Note: Replace backend with your project name if different. On Windows, the Python path uses venv/Scripts/python.exe.