代码:
from django.core.management.base import BaseCommand, CommandError
from django.db import models
#from placeholders import *
import os
import time
import logging
from django.utils.log import getLogger #from file_protect.views import logger
#logger = logging.getLogger("file_protect.alarm_handler")
#logger = logging.getLogger("file_protect.views")
logger = getLogger('root') class Command(BaseCommand):
def handle(self, *args, **options):
print 'hello, django!'
while(True):
logger.info("hello, django")
print 'hello, django!'
time.sleep()
参考资料:
http://www.th7.cn/Program/Python/201607/902253.shtml
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/