2011-02-17 73 views
0

我正在通過Django教程並使用PyDev Eclipse插件進行開發。PyDev與Django問題的inteactive shell

對於交互式測試,我使用「使用Django交互式shell」,通過右鍵單擊PyDev項目 - > Django - >使用Django環境的Shell。

這裏是我所遇到的問題(「lemonanas」是我的項目名稱,「民意調查」是我的應用程序名稱):

>>from lemonanas.polls.models import Poll, Choice 
>>Poll.objects.filter(id=1) 
Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
    File "F:\Python27\lib\site-packages\django\db\models\manager.py", line 141, in filter 
    return self.get_query_set().filter(*args, **kwargs) 
    File "F:\Python27\lib\site-packages\django\db\models\query.py", line 561, in filter 
    return self._filter_or_exclude(False, *args, **kwargs) 
    File "F:\Python27\lib\site-packages\django\db\models\query.py", line 579, in _filter_or_exclude 
    clone.query.add_q(Q(*args, **kwargs)) 
    File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1170, in add_q 
    can_reuse=used_aliases, force_having=force_having) 
    File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1058, in add_filter 
    negate=negate, process_extras=process_extras) 
    File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1225, in setup_joins 
    field, model, direct, m2m = opts.get_field_by_name(name) 
    File "F:\Python27\lib\site-packages\django\db\models\options.py", line 296, in get_field_by_name 
    cache = self.init_name_map() 
    File "F:\Python27\lib\site-packages\django\db\models\options.py", line 326, in init_name_map 
    for f, model in self.get_all_related_m2m_objects_with_model(): 
    File "F:\Python27\lib\site-packages\django\db\models\options.py", line 401, in get_all_related_m2m_objects_with_model 
    cache = self._fill_related_many_to_many_cache() 
    File "F:\Python27\lib\site-packages\django\db\models\options.py", line 415, in _fill_related_many_to_many_cache 
    for klass in get_models(): 
    File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 167, in get_models 
    self._populate() 
    File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in _populate 
    self.load_app(app_name, True) 
    File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 76, in load_app 
    app_module = import_module(app_name) 
    File "F:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module 
    __import__(name) 
ImportError: No module named polls 

如果我使用默認的shell,執行「manage.py殼」 - 一切正常。但是默認shell並不像「與Django交互的shell」那麼舒服。

我注意到「與Django的交互式shell」不會將我的應用程序文件夾(輪詢)添加到python路徑。我想這是問題的本質。但不知道如何完全解決所有「import/pythonpath/etc」。 「與Django交互式shell」的問題。 希望你能幫助我。 謝謝。

回答

2

自定義python路徑,eclipse用來包含項目的路徑。 (不是每個應用程序,只需將項目文件夾 - 包含settings.py的一個)

+0

它的工作原理。非常感謝你。 – Alexander 2011-02-17 20:54:11

0

在Eclipse中,右鍵點擊你的項目,轉到PyDev->設置爲源文件夾