显示在heroku上部署的Django管理员名称(Display names in Django admin deployed on heroku)

编程入门 行业动态 更新时间:2024-10-27 14:26:08
显示在heroku上部署的Django管理员名称(Display names in Django admin deployed on heroku)

我在heroku上部署了一个django应用程序。 如果我访问/管理我的应用程序并登录,

我在这里显示的是Category对象而不是类别的实际名称,尽管我在models.py中提到过它。

class Category(models.Model): name = models.CharField(max_length=128) abbr = models.CharField(max_length=5) sales_price = models.FloatField() def __unicode__(self): return self.name

我已经通过管理界面本身添加了这些类别对象。 这可能与显示器有关吗?

I have deployed a django app on heroku. If i visit /admin of my app and login,

I am getting Category object displayed here instead of the actual name of the category, though I have mentioned it in models.py.

class Category(models.Model): name = models.CharField(max_length=128) abbr = models.CharField(max_length=5) sales_price = models.FloatField() def __unicode__(self): return self.name

I have added those category objects through the admin interface itself. Might this have anything to do with the display?

最满意答案

您应该确保在开发中运行与Heroku相同版本的Python。

在这里你显然使用的是Python 3,因此你应该在模型类中定义__str__而不是__unicode__ 。

You should ensure you are running the same version of Python in development as in Heroku.

Here you are obviously using Python 3, so you should define __str__ in your model class instead of __unicode__.

更多推荐

本文发布于:2023-07-20 11:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1198688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理员   名称   Django   heroku   deployed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!