开发者

Import error in django

开发者 https://www.devze.com 2023-01-06 12:17 出处:网络
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

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
     ImportErro开发者_如何学Cr: cannot import name MultilingualModel

How to resolve this?


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

import multiling
print multiling.__file__


Don't use a module name 'test', as it conflicts with python's test module.


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...


from multiling import MultilingualModel shows error because multiling is a another code which you are trying to import please include that in your directory and then try.

0

精彩评论

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

关注公众号