Google App Engine(Python)导入失败

2024-03-29 00:30:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我的文件结构如下:

app.yaml
something/
    __init__.py
    models.py
    test.py

我已将URL设置为在app.yaml中运行tests.py

^{pr2}$

test.py进口models.py

当我试图导航到http://myapp.appspot.com/test/时,我得到以下错误:

Error: Server Error The server encountered an error and could not complete your request. If the problem persists, please report your problem and mention this error message and the > query that caused it

当我检查仪表板上的日志时,我看到发生了以下错误:

<type 'exceptions.ImportError'>: No module named models

如何正确导入文件?在

干杯

皮特


Tags: and文件thepytestappyamlyour
3条回答

内部测试.py你可以在上面写一些东西,比如:

from something.models import *

这将导入模型。 不过,对于更正代码,通配符“*”不是很好,您可以显式导入使用的模型:

^{pr2}$

等等。在

尝试按如下方式导入models

import something.models as models

在测试.py应该有imports models,而不是{}

相关问题 更多 >