J'ai un problème lors de l'exécution de ma commande personnalisée, car elle lancera une erreur NameError: le nom global "graphofknowledge" n'est pas défini. Ma structure de fichier estLes commandes de gestion Django ne peuvent pas trouver mon application
projectFile |-manage.py |-.. |-graphofknowledge (app) |-models.py |-views.py |-management |-__init__.py |-commands |-__init__.py |-customCommand.py
Voici le code pour ma commande personnalisée
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)
j'ai ajouté le nom de l'application dans le INSTALLÉ APP. Cela fonctionne quand je lance une impression dans la commande personnalisée. Mais une fois que j'ajoute l'instruction import pour mes modèles, elle lancera NameError. Puis-je savoir comment puis-je résoudre ce problème?
Salut, pouvez-vous s'il vous plaît coller la trace de pile d'exception? Quelle version de Django et python? –
@Mauro Rocco python 2.7 et django 1.5.6 – LeonBrain
Ajoutez votre trace de pile à la question s'il vous plaît sinon personne ne sera en mesure d'aider ici. –