DEBUG, SECRET_KEY ve ALLOWED_HOSTS
Tehlikeli ayarları doğru yapılandırın.
DEBUG, SECRET_KEY ve ALLOWED_HOSTS, CoddyKit'te ücretsiz bir Django Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Django Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Django Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Three Dangerous Settings
Three settings in settings.py can sink a production site if you get them wrong. Let us tame DEBUG, SECRET_KEY, and ALLOWED_HOSTS together. 🔒
What DEBUG Does
When DEBUG is True, Django shows detailed error pages with your code, settings, and traceback. That is gold in dev but a gift to attackers in production.
DEBUG = TrueTurn DEBUG Off in Production
In production, set DEBUG to False so users see a generic 500 page instead of your internals. Never ship a live site with DEBUG on.
DEBUG = FalseMeet SECRET_KEY
The SECRET_KEY is the seed Django uses to sign sessions, CSRF tokens, and password resets. Leak it and an attacker can forge any of them.
SECRET_KEY = "django-insecure-..."Keep SECRET_KEY Secret
Never commit your real SECRET_KEY to git. Load it from an environment variable so the value lives outside your code.
import os
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]Generate a Strong Key
Need a fresh SECRET_KEY? Django ships a helper that returns a long, random, hard-to-guess string for you to store securely.
from django.core.management.utils import get_random_secret_key
get_random_secret_key()Why ALLOWED_HOSTS Exists
ALLOWED_HOSTS lists the domains your site is allowed to serve. It blocks HTTP Host header attacks that try to trick your app with a fake hostname.
Set Your Real Domains
Fill ALLOWED_HOSTS with the exact domains your site answers to. With DEBUG off, any request to an unlisted host gets a 400 error.
ALLOWED_HOSTS = ["example.com", "www.example.com"]Avoid the Wildcard Trap
Setting ALLOWED_HOSTS to the wildcard accepts any host header and defeats the protection. Use it only for quick local tests, never in production.
ALLOWED_HOSTS = ["*"]Drive It All From Env
The clean pattern is one source of truth: read DEBUG, SECRET_KEY, and hosts from environment variables so the same code runs safely everywhere.
DEBUG = os.environ.get("DEBUG", "0") == "1"Let Django Warn You
Django can audit these settings for you. The check --deploy command flags an unsafe DEBUG, weak key, or open hosts before you ship.
python manage.py check --deployQuick Check
Time to test your instinct about production settings.
Recap: The Safe Trio
You locked down the basics: DEBUG off, a secret key kept out of git, and ALLOWED_HOSTS scoped to your domains. Run check --deploy and you are off to a safe start. 🎉
Sıkça Sorulan Sorular
“DEBUG, SECRET_KEY ve ALLOWED_HOSTS” dersi ücretsiz mi?
Evet — “DEBUG, SECRET_KEY ve ALLOWED_HOSTS” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Django Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Django Academy kursu toplamda 4 dersten oluşur.
“DEBUG, SECRET_KEY ve ALLOWED_HOSTS” dersinde ne öğreneceğim?
Tehlikeli ayarları doğru yapılandırın. Django Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Django Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Django Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“DEBUG, SECRET_KEY ve ALLOWED_HOSTS” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Django Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Django Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- DEBUG, SECRET_KEY ve ALLOWED_HOSTS
- HTTPS, HSTS ve Güvenli Çerezler
- XSS, CSRF ve SQL Injection Savunmaları
- Dağıtım Kontrol Listesini Uygulama