pip install django
?
django-admin startproject web
cd web
python manage.py runserver
执行数据库迁移生成数据表
python manage.py migrate
创建一个管理员用户
python manage.py createsuperuser
python manage.py runserver
?访问http://127.0.0.1:8000/admin/,使用创建的用户名密码登录
python manage.py startapp phone
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)
python manage.py makemigrations
python manage.py migrate
?