Python:Django创建第一个项目
os:win10
python 3.9
Django 4.0.4
pip安装Django 4.0.4
pip install Django==4.0.4
4.0.4是版本号,也可以不指定版本安装:
pip install Django
环境安装好后,命令行终端创建第一个项目:
django-admin startproject projectName
项目文件结构如下:
─projectName
│ manage.py --命令行工具,可以各种方式与该 Django 项目进行交互,如启动项目等
│
└─projectName
asgi.py
settings.py --该 Django 项目的配置
urls.py
运行创建的Django项目:
进入第一级projectName目录(有manage.py文件),执行启动命令:
./manage.py runserver 127.0.0.1:8000
执行后会在新cmd窗口启动项目:
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. May 01, 2022 - 20:09:09 Django version 4.0.4, using settings 'prijectName.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
提示如上信息后,在浏览器ip:port问即可。