简体   繁体   中英

Import error in django

I am trying to understand how the django multilanguage feature works and I found this example

What I have done is created a test project and included that in settings.py

In the test directory I have multilingual.py and models.py (available at the link above).

But when I run python manage.py in the shell I get the following traceback:

>>> from test.models import Language
     Traceback (most recent call last):
     File "<console>", line 1, in ?
     File "/opt/Project_Apr22/site/test/models.py", line 2, in ?
     from multiling import MultilingualModel
     ImportError: cannot import name MultilingualModel

How to resolve this?

从multiling导入MultilingualModel显示错误,因为multiling是您要导入的另一个代码,请将其包含在目录中,然后尝试。

Are you sure that you're importing from the multiling that you think you are?

import multiling
print multiling.__file__

不要使用模块名称“ test”,因为它与python的测试模块冲突。

First of all: which version of django?

For me (django 1.2) Your code dies because multiling.py is at the root of the project. Not sure is it django bug, multiling bug or bug of both.

After adding add app_label in MultilingualModel.Meta :

class MultilingualModel(models.Model):

    # ...

    class Meta:
        app_label = 'foo'
        abstract = True

everything works. I am thinking it is Django's bug. You (or maybe I) should report it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM