0

在本地我使用 sqllite3 作为数据库,但在生产中我使用 MySQL。当我将项目转移到生产环境时,我遇到了这个错误:

  ...
File "S:\Python27\lib\site-packages\django\templatetags\i18n.py", line 46, in
render
    langs = self.languages.resolve(context)
  File "S:\Python27\lib\site-packages\django\template\base.py", line 653, in res
olve
    value = self._resolve_lookup(context)
  File "S:\Python27\lib\site-packages\django\template\base.py", line 692, in _re
solve_lookup
    raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current
)) # missing attribute
VariableDoesNotExist: Failed lookup for key [LANGUAGES] in u'[{}, {}, {}]'

我正在使用 django 的 i18n

关于这是来自哪里的任何想法?谷歌并没有提供太多信息,还有哪些数据对调试有用?我将本地测试环境指向生产数据库并得到了同样的错误。

我在 settings.py 中的 LANGUAGES 变量是:

LANGUAGES = (
    ('en',gettext('English')),
    ('fr',gettext('French')),
)

编辑 打开调试,我收到错误:

Caught OperationalError while rendering: (1242, 'Subquery returns more than 1 row')

在线上{% for f in frames %}

我的框架模型是:

@I18n('title','description')
class Collection(models.Model):
    title = models.CharField(max_length=255)
    description = models.CharField(max_length=255)
    order = models.IntegerField(default=100)
    image = models.ImageField(upload_to="collection/images",null=True)
    rollover = models.ImageField(upload_to="collection/images",null=True,blank=True)
    publish = models.BooleanField(default=True)

    def __unicode__(self):
        return self.title

@I18n('title')
class Frame(models.Model):
    title = models.CharField(max_length=255)
    collection = models.ManyToManyField(Collection)
    order = models.IntegerField(default=100)
    image = models.ImageField(upload_to="frame/images")
    rollover = models.ImageField(upload_to="frame/images",null=True,blank=True)
    publish = models.BooleanField(default=True)

    def __unicode__(self):
        return self.title

编辑#2

麻烦的 MySQL 行,在 SQLite 中不会失败

SELECT `FrontEnd_article`.`id`, `FrontEnd_article`.`title_fr`, `FrontEnd_article`
.`title_en`, `FrontEnd_article`.`text_fr`, `FrontEnd_article`.`text_en`, 
`FrontEnd_article`.`date`, `FrontEnd_article`.`image`, `FrontEnd_article`.`image_text`, 
`FrontEnd_article`.`can_comment`, `FrontEnd_article`.`order`, 
`FrontEnd_article`.`publish` FROM `FrontEnd_article` INNER JOIN 
`FrontEnd_article_frames` ON (`FrontEnd_article`.`id` = 
`FrontEnd_article_frames`.`article_id`) WHERE `FrontEnd_article_frames`.`frame_id` =  
(SELECT U0.`id` FROM `FrontEnd_frame` U0 INNER JOIN `FrontEnd_frame_collection` U1 ON 
(U0.`id` = U1.`frame_id`) WHERE (U1.`collection_id` = 1  AND U0.`publish` = True )) 
ORDER BY `FrontEnd_article`.`date` DESC

再次感谢您的帮助!

4

2 回答 2

2

如果临时启用 DEBUG,回溯是否相同?禁用时,错误消息可能会产生误导。这也可能是一个错误的数据库设置,Django 在不同的阶段退出。

于 2011-05-30T20:26:23.073 回答
0
SELECT * FROM FrontEnd_article INNER JOIN FrontEnd_article_frames ON 
(FrontEnd_article.id = FrontEnd_article_frames.article_id) WHERE 
FrontEnd_article_frames.frame_id = (SELECT U0.id FROM FrontEnd_frame U0 INNER JOIN 
FrontEnd_frame_collection U1 ON (U0.id = U1.frame_id) WHERE (U1.collection_id = 1  AND 
U0.publish = True ))

这是 Django 生成的简化版本。当我分解这个查询时,我意识到内部连接假设只返回 1 个值:

(SELECT U0.id FROM FrontEnd_frame U0 INNER JOIN FrontEnd_frame_collection U1 ON 
(U0.id = U1.frame_id) WHERE (U1.collection_id = 1  AND U0.publish = True ))

这实际上返回了一组结果数据。一旦我找到它,修复就很简单,我用“IN”替换了“=”,它工作正常。

FrontEnd_article_frames.frame_id IN (SELECT U0.id FROM FrontEnd_frame U0 INNER JOIN
FrontEnd_frame_collection U1 ON (U0.id = U1.frame_id) WHERE (U1.collection_id = 1  AND 
U0.publish = True ))
于 2011-05-31T13:55:59.610 回答