我在python中对待unicode有点不对劲。在Django中,我的部分模型和代码如下所示。你知道吗
class MyTest(models.Model):
address = models.CharField(max_length=100)
def __unicode__(self):
return u'%s,%s' % (self.address, self.city)
我通过csv加载这些值。你知道吗
records = csv.DictReader(self.cleaned_data["file"])
for line in records:
mt = MyTest()
mt.address=line['ADDRESS'],
mt.city=line['CITY'],
....
mt.save()
print line['ADDRESS']
print mt.address
70 Mall Rd
('70 Mall Rd',)
问题是,在管理模板中,我所有的值都有括号。就像
('LARGO',), ('FL',),
可能出了什么问题。你知道吗
谢谢。你知道吗
它是只有一个元素的元组,因为在第
mt.address=line['ADDRESS'],
行和第mt.city=line['CITY'],
行中添加了逗号例如:
相关问题 更多 >
编程相关推荐