Use django function for secret_key generation (#12999)

This commit is contained in:
Oliver authored and GitHub committed 2026-10-13 13:15:06 +11:00
1 parent 55ad065a60
commit bdcba5cbb9
1 file changed
+4 -5
+4 -5
View File
@@ -4,9 +4,7 @@ import datetime
import json
import logging
import os
import random
import shutil
import string
import sys
from pathlib import Path
from typing import Any, Optional
@@ -448,9 +446,10 @@ def get_secret_key(return_path: bool = False) -> str | Path:
logger.info("Generating random key file at '%s'", secret_key_file)
ensure_dir(secret_key_file.parent)
# Create a random key file
options = string.digits + string.ascii_letters + string.punctuation
key = ''.join([random.choice(options) for _idx in range(100)])
# Create a random key file (using a cryptographically secure generator)
from django.core.management.utils import get_random_secret_key
key = get_random_secret_key()
secret_key_file.write_text(key)
if return_path: