开发者

Google App Engine (Python) - Import Fails

I have a file structure like so:

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

I have URL set up to run tests.py in app.yaml:

...
- url: /test
  script: something/test.py

test.py imports models.py

When I try to navigate to http://myapp.appspot.com/test/ I get the following error:

Error: Server Error The server enco开发者_JS百科untered 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

And, when I check the logs on the dashboard I see the following error occurred:

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

How do I import the file properly?

Cheers,

Pete


inside test.py you can write at the top something like:

from something.models import *

This will import your models. For corrective code though - the wildcard '*' is not great and you explicitly import the models your using:

from something.models import ModelName, OtherModel

and so on.


test.py should have imports models, not imports models.py


Try to import models like this:

import something.models as models
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜