1、创建PyCharm项目

2、安装框架
python
pip install django==4.2.0

3、查看安装的包列表

4、使用命令创建django项目
python
django-admin startproject web

5、目录结构

6、运行
python
cd web
python manage.py runserver

7、初始化后台登录的用户名密码
执行数据库迁移生成数据表
python
python manage.py migrate
创建一个管理员用户
python
python manage.py createsuperuser
8、重启服务
python
python manage.py runserver
访问http://127.0.0.1:8000/admin/,使用创建的用户名密码登录

9、创建App来完成不同模块的开发
python
python manage.py startapp phone

10、应用创建的App到项目中

11、修改phone应用中models.py
python
from django.db import models
# Create your models here.
# 创建数据库数据模型对象的文件
class CreateUpdate(models.Model):
create_at = models.DateTimeField(auto_now_add=True)
update_at = models.DateTimeField(auto_now=True)
class Meta: # 元数据,除了字段以外的所有属性
# 设置model为抽象类,指定该表不应该在数据库中创建
abstract = True
class Post(CreateUpdate): # 继承基类
"""
Post模型类
"""
title = models.CharField(max_length=30)
content = models.TextField(max_length=255)
12、执行生成数据迁移文件并创建数据表
python
python manage.py makemigrations
python
python manage.py migrate

13、Django数据交互API

14、依次修改





15、访问http://127.0.0.1/phone/
