Skip to main content
 首页 » 编程设计

python之Django : import problem with python-twitter module

2025年05月04日27kerrycode

当我尝试在我的应用程序中导入 python-twitter 模块时,django 尝试导入 django.templatetags.twitter 而不是 python-twitter 模块(在/usr/lib/python2.5/site-packages/twitter.py 中) ,但我不知道为什么。 :s

例如:

myproject/ 
    myapp/ 
        templatetags/ 
            file.py 

在 file.py 中:

import twitter # this imports django.templatetags.twitter 

有什么办法可以解决吗?

非常感谢:)

编辑:我发现了问题。我的 templatetags 文件被命名为“twitter.py”。我已将其重命名为“twitter_tags.py”,现在可以使用了。 :)

请您参考如下方法:

The submodules often need to refer to each other. For example, the surround module might use the echo module. In fact, such references are so common that the import statement first looks in the containing package before looking in the standard module search path. source

因此,您需要使用绝对导入。

from some.other.pkg import twitter