主页没有问题208.12.29CLASS306。整个WEB已经可以运行了,但是还是有小BUG

后端的登录页面代码208.12.29CLASS306。整个WEB已经可以运行了,但是还是有小BUG

# base.html
 <!-- User image -->
                            <li class="user-header">
                                <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=609380044,682012158&fm=26&gp=0.jpg"
                                     class="img-circle" alt="User Image">
                                <p>
                                    {{ user.username }}
                                    <small>帅的惊动了全国人民</small>
                                </p>
                            </li>

前端的img src是写死的,这样无论谁登录都是这个图片,这是不正确的。
1.重新建造一个客户登录页面,让客户上传图片。但是,这样又要重复写前端页面烦死了。
2.所以我进行了取巧,在数据库里面多加了一个image的image = models.TextField(null=True)的模型。

image = models.TextField(null=True)
class User(AbstractBaseUser,PermissionsMixin):
    # 我们不使用默认的自增长的主键
    # id:100,101,102,103
    # uuid/shortuuid
    # Shortuuidfield:pip install django-shortuuidfield
    uid = ShortUUIDField(primary_key=True)
    telephone = models.CharField(max_length=11,unique=True)
    image = models.TextField(null=True)
    email = models.EmailField(unique=True,null=True)
    username = models.CharField(max_length=100)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)
    data_joined = models.DateTimeField(auto_now_add=True)

    USERNAME_FIELD = 'telephone'
    # telephone,username,password
    REQUIRED_FIELDS = ['username']
    EMAIL_FIELD = 'email'

    objects = UserManager()

    def get_full_name(self):
        return self.username

    def get_short_name(self):
        return self.username

前端修改后的代码

   <!-- User image -->
                            <li class="user-header">
                                <img src="{{ user.image }}"
                                     class="img-circle" alt="User Image">
                                <p>
                                    {{ user.username }}
                                    <small>帅的惊动了裤裆</small>
                                </p>
                            </li>

这样头像和名字都是活的了。

相关文章:

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