Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django仍然不适合我_Python_Django_Unicode - Fatal编程技术网

Python Django仍然不适合我

Python Django仍然不适合我,python,django,unicode,Python,Django,Unicode,我使用django1.6和python2.7,在models.py中有以下内容 class Recommend(models.Model): id = models.IntegerField(primary_key=True) master_id = models.IntegerField() movie_id = models.IntegerField() enable = models.TextField() # This field type is a gu

我使用django1.6和python2.7,在models.py中有以下内容

class Recommend(models.Model):
    id = models.IntegerField(primary_key=True)
    master_id = models.IntegerField()
    movie_id = models.IntegerField()
    enable = models.TextField() # This field type is a guess.
    class Meta:
        managed = False
        db_table = 'recommend'
    def __unicode__(self):
        return u'%s %s' % (self.id, self.master_id)
然而,结果仍然令人失望

>>> from movies.models import Recommend
>>> Recommend.objects.all()
[<Recommend: Recommend object>]
>>>
来自movies.models的
>>
>>>推荐.objects.all()
[]
>>>
我查过。没有一个对我有用。

用这个

from __future__ import absolute_import, division
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible
class Recommend(models.Model):
  id = models.IntegerField(primary_key=True)
  master_id = models.IntegerField()
  movie_id = models.IntegerField()
  enable = models.TextField() # This field type is a guess.

  class Meta:
    managed = False
    db_table = 'recommend'

  def __str__(self):
   return u'%s %s' % (self.id, self.master_id)

可能会有帮助

您的缩进在实际代码中是否正确?您在问题中粘贴的方式无效。@BurhanKhalid我编写的实际代码是正确的,此页上的格式没有缩进。请编辑您的问题,使缩进与代码中的缩进完全相同。谢谢,但仍然无效。我使用的是python2.7而不是python3,所以可能“from django.utils.encoding import python\u 2\u unicode\u compatible”不起作用。让我试试。