0Pricing
Django Academy · 课时

浏览 settings.py

了解每个项目都依赖的关键设置

浏览 settings.py 是 CoddyKit 上的免费 Django Academy 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Django Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Django Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

One File, Whole Project

The settings.py file is the control panel for your entire project. Nearly every Django behavior is configured from this one place. 🎛️

It Is Just Python

Settings are plain Python variables, so you can compute them with code. That flexibility is powerful, but it means typos break startup loudly.

BASE_DIR Anchors Paths

BASE_DIR points to your project root. Other settings build paths from it so your app works no matter where it is installed.

BASE_DIR = Path(__file__).resolve().parent.parent

DEBUG Controls Detail

DEBUG shows rich error pages while you build. You must set it to False in production, or you leak sensitive details to visitors. ⚠️

DEBUG = True

SECRET_KEY Signs Things

The SECRET_KEY secures sessions, cookies, and password resets. Keep it private and never commit the real one to version control.

ALLOWED_HOSTS Guards Access

ALLOWED_HOSTS lists the domains your site may serve. It blocks requests with a faked Host header, an important safety check.

ALLOWED_HOSTS = ["example.com"]

INSTALLED_APPS Lives Here

The familiar INSTALLED_APPS list sits in settings too. It declares which apps, yours and Django's, are active in this project.

MIDDLEWARE Wraps Requests

The MIDDLEWARE list defines layers that process every request and response, handling things like security and sessions in order.

DATABASES Defines Storage

The DATABASES setting tells Django where to store data. New projects start with SQLite, a simple file-based database.

DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}

TEMPLATES and Static

TEMPLATES configures HTML rendering, while STATIC_URL sets where CSS and JS are served from. Both shape how pages reach the browser.

Locale and Time

Settings like TIME_ZONE and LANGUAGE_CODE control formatting and translation, so your app feels right for its users worldwide. 🌍

TIME_ZONE = "UTC"

Quick Check

Which setting must be False before you go live?

Recap: You Know the Panel

You toured settings.py: BASE_DIR, DEBUG, SECRET_KEY, ALLOWED_HOSTS, apps, middleware, and databases. This file steers the whole project. 🧭

常见问题解答

「浏览 settings.py」课时是免费的吗?

是的 — 「浏览 settings.py」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Django Academy 课程的其余内容,请升级到 CoddyKit PRO。 Django Academy 课程共包含 4 节课。

「浏览 settings.py」这节课中我会学到什么?

了解每个项目都依赖的关键设置 你通过在浏览器中直接运行的动手代码来练习 Django Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Django Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Django Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「浏览 settings.py」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Django Academy 课中编写并运行代码吗?

能。每节 Django Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. startapp 与应用文件夹布局
  2. 在 INSTALLED_APPS 中注册应用
  3. 浏览 settings.py
  4. manage.py:您的命令中心
← 返回 Django Academy