我寫在位於應用程序direcroty一個utils.py這funcion:導入錯誤的models.py
from bm.bmApp.models import Client
def get_client(user):
try:
client = Client.objects.get(username=user.username)
except Client.DoesNotExist:
print "User Does not Exist"
return None
else:
return client
def to_safe_uppercase(string):
if string is None:
return ''
return string.upper()
然後當我使用功能to_safe_uppercase在我的models.py文件,通過將其導入這種方式:
from bm.bmApp.utils import to_safe_uppercase
我得到了蟒蛇錯誤:
from bm.bmApp.utils import to_safe_uppercase
ImportError: cannot import name to_safe_uppercase
我得到這個問題的解決方案時,我變化率T他進口的聲明爲:
from bm.bmApp.utils import *
但我不明白爲什麼這是爲什麼當我導入特定功能時,我得到了錯誤?
這不應該發生。我懷疑還有其他事情正在發生。 – Marcin 2012-04-18 15:41:40
不幸的是,django默認捕獲ImportErrors並用這個錯誤消息替換它們。嘗試修補django,以便它給你回溯,這應該指向問題。我懷疑循環進口或類似的東西。 – ch3ka 2012-04-18 15:46:48
@ ch3ka補丁django不是一個好主意......他也已經獲得了python追溯。當然,他在問題 – Jiaaro 2012-04-18 15:48:02