當我啓動本地開發服務器(./manage runserver
)時,settings.py會運行四次。我注意到,因爲錯誤/調試消息被打印了四次。我的settings.py被調用4次 - 任何想法爲什麼?
任何想法如何能來?我什至不知道從哪裏開始尋找。這對我很重要,因爲我正在努力設置Sentry,它不會像現在那樣報告站點的任何錯誤。
更新:
我檢查了導入模塊import settings
,在我的應用程序中沒有。
然後我說
import traceback; traceback.print_stack(); print
到settings.py中。其結果是:
File "./manage.py", line 5, in <module>
import settings # Assumed to be in the same directory.
File "(...)/myapp/settings.py", line 4, in <module>
import traceback; traceback.print_stack(); print
File "./manage.py", line 12, in <module>
execute_manager(settings)
(...)
File "(...)/site-packages/django/conf/__init__.py", line 73, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "(...)/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "(...)/myapp/../myapp/settings.py", line 4, in <module>
import traceback; traceback.print_stack(); print
File "./manage.py", line 5, in <module>
import settings # Assumed to be in the same directory.
File "(...)/myapp/settings.py", line 4, in <module>
import traceback; traceback.print_stack(); print
File "./manage.py", line 12, in <module>
execute_manager(settings)
(...)
File "(...)/site-packages/django/conf/__init__.py", line 73, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "(...)/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "(...)/myapp/../myapp/settings.py", line 4, in <module>
import traceback; traceback.print_stack(); print
這是預期的行爲?如果不是,我怎麼能找到我的錯誤?
非常感謝您的分析和確認。我必須在幾天內回到這個問題。關於import_count只是一個想法:我認爲它應該總是返回1,如果你分配0,然後加1。可選方法:'try:import_count + = 1,除了NameError:import_count = 0'。再次感謝您幫助我瞭解settings.py ... – jammon 2011-06-29 18:58:08