預期以下工作:crontab的蟒蛇Django的問題
*/1 * * * * python /usr/share/str8RED/manage.py getLiveResults
使用下面的鏈接,我已經成功地創建一個錯誤日誌:
python /usr/share/str8RED/manage.py getLiveResults
然而,當我用下面的cronjob沒有任何反應:
http://matthewwittering.com/blog/django-tips/running-a-django-management-commands-with-crontab.html
這告訴我說:
Traceback (most recent call last):
File "/usr/share/str8RED/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
我能得到cronjab的工作和運行與之呼應的 「Hello World」 的每一分鐘。任何幫助將不勝感激,非常感謝,艾倫。
getLiveResults.py的內容:
from django.core.management import BaseCommand
from straightred.models import StraightredTeam
from straightred.xmlsoccer import XmlSoccer
#The class must be named Command, and subclass BaseCommand
class Command(BaseCommand):
# Show this when the user types help
help = "My test command"
# A command must define handle()
def handle(self, *args, **options):
xmlsoccer = XmlSoccer(api_key='XYZ', use_demo=False)
teams = xmlsoccer.call_api(method='GetAllTeamsByLeagueAndSeason',
seasonDateString='1617',
league='English League Championship')
numberOfTeamsUpdated = 0
for team in teams:
if '{http://xmlsoccer.com/Team}Team_Id' in team.keys():
teamUpdate = StraightredTeam(teamid=team['{http://xmlsoccer.com/Team}Team_Id'],
teamname=team['{http://xmlsoccer.com/Team}Name'],
country=team['{http://xmlsoccer.com/Team}Country'],
stadium=team['{http://xmlsoccer.com/Team}Stadium'],
homepageurl=team['{http://xmlsoccer.com/Team}HomePageURL'],
wikilink=team['{http://xmlsoccer.com/Team}WIKILink'],
currentteam=1)
teamUpdate.save()
numberOfTeamsUpdated = numberOfTeamsUpdated + 1
self.stdout.write("Hello world!")
什麼'getliveResults'呢? –
如果您使用的是虛擬環境,那麼您需要激活環境, –