1.创建项目:
命令:django-admin startproject 项目名
创建成功后如下图所示。
H:\use_by_myself\demo>django-admin startproject project_demo
2.查询当前目录:
命令:dir
2022/01/20 13:20 <DIR> ..
2022/01/20 13:24 <DIR> .idea
2022/01/20 17:59 <DIR> project_demo
0 个文件 0 字节
4 个目录 7,734,820,864 可用字节
3.启动运行:
命令:python manage.py runserver
启动成功如下图。
划重点:只有当dir可以看到manage.py文件才可以启动(cd到项目根目录)
2022/01/20 17:59 <DIR> project_demo
1 个文件 690 字节
3 个目录 7,733,248,000 可用字节
H:\use_by_myself\demo\project_demo>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 20, 2022 - 18:16:38
Django version 3.1.7, using settings 'project_demo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
点开服务器网址:
4.创建子应用
命令:python manage.py startapp 子应用名
H:\use_by_myself\demo\project_demo>python manage.py startapp user
5.子应用注册:
settings.py→INSTALLEN_APPS→列表末尾添加 应用名.apps.类名(末尾记得加逗号)