startapp 与应用文件夹布局
了解应用中每个生成文件的用途
startapp 与应用文件夹布局 是 CoddyKit 上的免费 Django Academy 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Django Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Django Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Apps Are the Building Blocks
A Django project is made of small, focused pieces called apps. Each app handles one feature, like a blog or a shop. 🧱
Create One with startapp
You make a new app with the startapp command. Django generates a ready-to-edit folder so you never start from a blank page.
python manage.py startapp blogThe App Folder Appears
That command drops a blog/ folder next to manage.py. Inside are several files, each with one clear job that you will meet next.
models.py Holds Your Data
The models.py file is where you describe your data as Python classes. Each class becomes a database table later on.
class Post(models.Model):
title = models.CharField(max_length=200)views.py Handles Requests
The views.py file holds the logic that runs when a page is requested. A view takes a request and returns a response.
def home(request):
return HttpResponse("Hello")admin.py Powers the Admin
The admin.py file lets you register models so they show up in Django's built-in admin site for easy editing.
admin.site.register(Post)apps.py Names the App
The apps.py file holds a small config class that gives your app its name and settings. You rarely touch it at first.
class BlogConfig(AppConfig):
name = "blog"tests.py for Confidence
The tests.py file is where your automated tests live. Writing tests here helps you change code without breaking things.
The migrations Folder
The migrations folder tracks how your database structure changes over time. Django fills it in automatically as your models evolve.
No urls.py Yet
Notice startapp does not create a urls.py for the app. You add one yourself when you want to route pages to your views.
Apps Are Reusable
Because each app is self-contained, you can lift a well-made app out of one project and drop it into another with little effort. ♻️
Quick Check
Which file does startapp create for your data models?
Recap: You Mapped an App
You ran startapp and learned each file's job: models for data, views for logic, admin and apps for config. Apps keep features tidy and reusable. 🎉
常见问题解答
「startapp 与应用文件夹布局」课时是免费的吗?
是的 — 「startapp 与应用文件夹布局」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Django Academy 课程的其余内容,请升级到 CoddyKit PRO。 Django Academy 课程共包含 4 节课。
「startapp 与应用文件夹布局」这节课中我会学到什么?
了解应用中每个生成文件的用途 你通过在浏览器中直接运行的动手代码来练习 Django Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Django Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Django Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「startapp 与应用文件夹布局」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Django Academy 课中编写并运行代码吗?
能。每节 Django Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- startapp 与应用文件夹布局
- 在 INSTALLED_APPS 中注册应用
- 浏览 settings.py
- manage.py:您的命令中心