0
我在運行自定義命令時遇到問題,因爲它會拋出一個NameError:全局名稱「graphofknowledge」未定義。我的文件結構是Django管理命令無法找到我的應用程序
projectFile |-manage.py |-.. |-graphofknowledge (app) |-models.py |-views.py |-management |-__init__.py |-commands |-__init__.py |-customCommand.py
這裏是我的自定義命令
from django.core.management.base import BaseCommand
from graphofknowledge.models import TagTrend_refine
class Command(BaseCommand):
args = '<foo bar ...>'
help = 'our help string comes here'
def loadTagTrend(self, fileName):
listOfData = []
f = open(fileName)
lines = f.readlines()
f.close()
for line in lines:
temp = line.strip().split("\t")
data = TagTrend_refine(
tag = temp[0],
trendData = temp[1]
)
listOfData.append(data)
TagTrend_refine.objects.bulk_create(listOfEntities)
def handle(self, *args, **options):
self.loadTagTrend(graphofknowledge/tagTrend_refine.txt)
我增加了應用程序的名稱到安裝的應用程序的代碼。當我在自定義命令中運行打印輸出時,它工作正常。但是,一旦我爲我的模型添加import語句,它將引發NameError。我可以知道我該如何解決這個問題?
嗨,你可以請粘貼異常堆棧跟蹤?哪個Django和python版本? –
@Mauro Rocco python 2.7和django 1.5.6 – LeonBrain
請將您的堆棧跟蹤添加到問題中,否則沒有人能夠在這裏提供幫助。 –