1、编写model

在web系统中,user表是第一个设计的,在django中有自带的user表
4-5 django在线教育平台------自定义userprofile
这是在线教育系统的user,自带的user表无法满足需求
4-5 django在线教育平台------自定义userprofile
所以需要自定义,执行startapp users,并在settings中注册新建的app
4-5 django在线教育平台------自定义userprofile
如果不配置AUTH_USER_MODEL = ‘users.UserProfile’会报以下错误
4-5 django在线教育平台------自定义userprofile

编写model,关于model类的编写可以参考官方文档中的 Field types和Field options
4-5 django在线教育平台------自定义userprofile
Model metadata is “anything that’s not a field”,翻译是:Model 元数据就是 “不是一个字段的任何数据”(不一定准确,还是直接看英文)
4-5 django在线教育平台------自定义userprofile

2、运行项目

model完成后执行makemigrations users, migrate users,根据提示输入yes
4-5 django在线教育平台------自定义userprofile

4-5 django在线教育平台------自定义userprofile
执行完操作后,数据库多了三张表
4-5 django在线教育平台------自定义userprofile
主要看users_userprofile这张表,表中有我们自己定义的字段,也有继承AbstractUser得来的字段
4-5 django在线教育平台------自定义userprofile
还有一个错误,根据错误提示安装Pillow,执行pip install pillow
4-5 django在线教育平台------自定义userprofile

相关文章:

  • 2021-12-19
  • 2021-12-19
  • 2021-05-14
  • 2021-09-15
  • 2021-11-19
  • 2021-11-19
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2021-10-15
  • 2021-12-29
  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
  • 2021-12-19
  • 2021-07-18
相关资源
相似解决方案