创建user应用,继承Abastract,配置media
-
创建应用
python ../../manage.py startapp user
-
在配置文件中注册应用
INSTALLED_APPS = ['user']
-
在models.py中,创建user表
from django.db import models from django.contrib.auth.models import AbstractUser class User(AbstractUser): mobile = models.CharField(max_length=11, unique=True) # 唯一,长度11 # 需要pillow包的支持 ImageField继承自FileField icon = models.ImageField(upload_to='icon', default='icon/default.png') class Meta: db_table = 'luffy_user' verbose_name = '用户表' verbose_name_plural = verbose_name def __str__(self): return self.username
-
在配置文件中自定义User表
AUTH_USER_MODEL = 'user.User' # 表名可以小写
-
在配置文件中,配置media
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
-
安装pillow,表迁移
pip install pillow python manage.py makemigrations python manage.py migrate