一、创建admin用户,到项目所在目录下输入python manage.py createsuperuser命令,我的项目名为djtest。然后输入新的用户名,密码等信息。

Django administration的使用(python)

二、运行项目

命令python manage.py runserver

Django administration的使用(python)

三、Ctrl+点击url网址,默认端口为8000

Django administration的使用(python)

四、在url网址后加上/admin,回车

Django administration的使用(python)

五、把Django administration界面改为中文版

到项目中把settings.py文件中的蓝色划线部分改为‘zh-cn’。如果你用的django是1.8以上版本则改为‘zh-hans’,重新加载页面

Django administration的使用(python)

Django administration的使用(python)

六、

settings.py设置中国所在时区

Asia/Shanghai

Django administration的使用(python)

七、注册

在admin.py中加入要注册的表,我的表名为BookInfo

Django administration的使用(python)

八、添加表数据信息

网页中出现表则注册成功,然后点击添加来添加数据

Django administration的使用(python)

Django administration的使用(python)

九、点击保存,报错

Unicode error hint

The string that could not be encoded/decoded was: 三国演绎

编码问题解决方法:return self.btitle.encode('utf-8'),把models.py中的带返回值的函数都改为utf-8编码

Django administration的使用(python)

十、添加进去的数据名为*** object怎么改为添加的名字

解决方法:在models.py文件定义表的类中添加__str__方法返回名字字段内容

def __str__(self):
        return self.hname.encode('utf-8')

 

Django administration的使用(python)

Django administration的使用(python)

相关文章:

  • 2022-12-23
  • 2021-12-16
  • 2021-04-01
  • 2021-07-17
  • 2021-06-26
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-28
  • 2022-12-23
  • 2022-01-14
  • 2021-07-31
  • 2021-04-28
  • 2021-08-03
  • 2022-12-23
相关资源
相似解决方案