Zum Hauptinhalt springen
Malware / Trojaner / VirenMATCHBOIL: New tricks, same old evil intentions(08.10.2026 um 10:45 Uhr)
•
Linux Tipps & HardeningLinux Archives and Compression Quiz: tar, gzip & zstd(09.10.2026 um 04:40 Uhr)
•
Linux Tipps & HardeningLinux Memory Pressure Explained: Reclaim, Swap, and OOM(09.10.2026 um 04:58 Uhr)
•
Windows Tipps & SecurityQuickAssist_UAC_Bypass(09.10.2026 um 02:42 Uhr)
•
Proof of Concept (PoC)PPLwindow(09.10.2026 um 03:42 Uhr)
•
Linux Tipps & HardeningMAccConc(09.10.2026 um 04:43 Uhr)
•••
AI & KI NachrichtenIT Security News Hourly Summary 2026-10-09 05h : 4 posts(09.10.2026 um 05:00 Uhr)
•
IT Security NachrichtenHow Hackers Exploit AI agents Claude Code Enterprise Network Intrusions(09.10.2026 um 04:31 Uhr)
•
Malware / Trojaner / VirenMATCHBOIL: New tricks, same old evil intentions(08.10.2026 um 10:45 Uhr)
•
Linux Tipps & HardeningLinux Archives and Compression Quiz: tar, gzip & zstd(09.10.2026 um 04:40 Uhr)
•
Linux Tipps & HardeningLinux Memory Pressure Explained: Reclaim, Swap, and OOM(09.10.2026 um 04:58 Uhr)
•
Windows Tipps & SecurityQuickAssist_UAC_Bypass(09.10.2026 um 02:42 Uhr)
•
Proof of Concept (PoC)PPLwindow(09.10.2026 um 03:42 Uhr)
•
Linux Tipps & HardeningMAccConc(09.10.2026 um 04:43 Uhr)
•••
AI & KI NachrichtenIT Security News Hourly Summary 2026-10-09 05h : 4 posts(09.10.2026 um 05:00 Uhr)
•
IT Security NachrichtenHow Hackers Exploit AI agents Claude Code Enterprise Network Intrusions(09.10.2026 um 04:31 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Update Django Key using .env

Laravel that I usually code has a command that updates the encryption key at .env file. To be honest, I love this approach and I wanted to replicate upon my…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

Laravel that I usually code has a command that updates the encryption key at .env file. To be honest, I love this approach and I wanted to replicate upon my django project.



Therefore, I followed these steps:






Step 1: Load .env file



See: https://dev.to/pcmagas/how-to-load-env-in-django-project-4c9d






Step 2: Use SECRET_KEY env file:



At settings.py Do:




SECRET_KEY = os.getenv('SECRET_KEY',None)

if SECRET_KEY is None:
raise RuntimeError("SECRET_KEY value is not defined upon .env file")









Step 3 Create a command that update the .env:



I made the script myapp/management/commands/mk_key.py with the following (replace myapp with your own application name):




from django.core.management.base import BaseCommand
from django.core.management.utils import get_random_secret_key
import os

class Command(BaseCommand):
help = 'Create a new Secret Key'

def handle(self, *args, **kwargs):

key = get_random_secret_key()
env_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',"..","..",'.env')
self.updateDotenv(env_file_path,key)

def updateDotenv(self,env_file_path,key):

with open(env_file_path, 'r') as file:
lines = file.readlines()

# Update the SECRET_KEY line
updated_lines = []

for line in lines:
if line.startswith('SECRET_KEY'):
continue
else:
updated_lines.append(line)

line = f"SECRET_KEY='{key}'\n"
updated_lines.insert(0,line) # Replace with new key

# Write the updated lines back to the .env file
with open(env_file_path, 'w') as file:
file.writelines(updated_lines)

# Output the new secret key
self.stdout.write(f"Updated .env\n")






Then run it as:




 python manage.py mk_key


🔍 CTI & Forensik

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar · Exploit-Belege
IoC Intelligence
1 Indikatoren · Defanged · STIX 2.1
dev[.]to
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
3 Knoten · 2 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Intelligence Digest — kostenlos Täglich die wichtigsten Security-News · jederzeit abbestellbar
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War diese Seite hilfreich?
0
Jetzt Bewertung abgeben
🟢 Niedrig (1-3.9) 🟡 Mittel (4.0-6.9) 🔴 Hoch (7.0-8.9) Kritisch (9.0-10.0)

Verwandte Story-Cluster & Quellen (Vektor-KI)

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Update Django Key using .env

Thematisch verwandte Begriffe: Update, Django, using · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag