我在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.nameI 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__.
更多推荐
发布评论