gpt4 book ai didi

python - smart_unicode 在我的 Django 项目中不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 20:37:30 25 4
gpt4 key购买 nike

我是 Django 的新手,陷入了一些幼稚的错误。我在我的模型中创建了一个项目名称“singup”并添加了一个“smart_unicode utility”,但不幸的是,在我的管理站点中我没有看到任何变化。我想将每个存储的注册称为电子邮件。

这是我的 models.py 文件:

from django.db import models
from django.utils.encoding import smart_unicode
# Create your models here.
class signup(models.Model):
first_name=models.CharField(max_length=12,null=False,blank=False)
last_name=models.CharField(max_length=12,null=False,blank=False)
email=models.EmailField(max_length=60,null=False,blank=False)
timestamp=models.DateTimeField(auto_now_add=True,auto_now=False)
updated=models.DateTimeField(auto_now_add=False,auto_now=True)


def __unicode__(self):
return smart_unicode(self.email)

这是我的admin.py

    from django.contrib import admin

# Register your models here.
from models import signup

class signupAdmin(admin.ModelAdmin):
class Meta:
model=signup
admin.site.register(signup,signupAdmin)

这是我的管理站点图片。

enter image description here

最佳答案

这是python 2.7以上的解决方案

from django.utils.encoding import smart_text

...

def __str__(self):
return smart_text(self.email)

关于python - smart_unicode 在我的 Django 项目中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33706373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com