2011-08-08 14 views
2

私は何が起こっているか見当がつかないトレースバック 奇妙なDjangoのインポートエラー私が何をしようとしていた何

Traceback (most recent call last): 
    File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\manage.py", line 14, in <module> 
    execute_manager(settings) 
    File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager 
    utility.execute() 
    File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "C:\Python26\lib\site-packages\django\core\management\base.py", line 220, in execute 
    output = self.handle(*args, **options) 
    File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle 
    self.run(*args, **options) 
    File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 78, in run 
    self.inner_run(*args, **options) 
    File "C:\Python26\lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run 
    self.validate(display_num_errors=True) 
    File "C:\Python26\lib\site-packages\django\core\management\base.py", line 249, in validate 
    num_errors = get_validation_errors(s, app) 
    File "C:\Python26\lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors 
    for (app_name, error) in get_app_errors().items(): 
    File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors 
    self._populate() 
    File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 64, in _populate 
    self.load_app(app_name) 
    File "C:\Python26\lib\site-packages\django\db\models\loading.py", line 78, in load_app 
    models = import_module('.models', app_name) 
    File "C:\Python26\lib\site-packages\django\utils\importlib.py", line 35, in import_module 
    __import__(name) 
    File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\shastra\models.py", line 10, in <module> 
    from fb_api.api import * 
    File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\api.py", line 7, in <module> 
    from fb_api.models import FbApiUser 
    File "C:\Documents and Settings\EC.32-SAMUEL\workspace\kiosk\..\kiosk\fb_api\models.py", line 41, in <module> 
    from shastra.models import Shastra 
ImportError: cannot import name Shastra 

Shastra

class Shastra(models.Model): 
    something = models.IntegerField() 

    def save(self, *args, **kwargs): 
     post_content(app='shastra', content=self) 
     super(Shastra, self).save(*args, **kwargs) 


# The function being called in the override function 

def post_content(*args, **kwargs): 
    FbApiContent(content = kwargs['content']).save() 


# The model being used by the override function 

from shastra.models import Shastra 

class FbApiContent(models.Model): 

    content = models.ForeignKey(Shastra) 

と呼ばれる私のモデルの一つの保存メソッドをオーバーライドすることでした。 |、何らかの洞察力を私は感謝します

答えて

7

円形輸入。解決するか、文字列をFK引数(models.ForeignKey('app.Shastra'))として使用してください。

3

あなたは循環インポートがあるようです。

shastra\models.pyfrom fb_api.api import *

fb_api\api.pyをやっていることは、あなただけのモジュールから1つのクラスをインポートする場合でもfrom shastra.models import Shastra

をやっているfrom fb_api.models import FbApiUser

fb_api\models.pyをやっている、全体のモジュールは、それの名前空間を埋めるために実行されます。

関連する問題