命令行执行Django脚本的方法

update.py
    import os
    import sys
    import django
    sys.path.append(r'C:\Users\Administrator\PycharmProjects\s6day109')

    os.chdir(r'C:\Users\Administrator\PycharmProjects\s6day109')
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "s6day109.settings")
    django.setup()

    from crm import models

    v = models.Customer.objects.all()
    print(v)

30 01 * * *  /usr/local/bin/python /usr/bin/update.py

服务:
yum install crontabs
    /sbin/service crond start //启动服务
    /sbin/service crond stop //关闭服务

vim /etc/crontab 
    30 01 * * *  /usr/local/bin/python /usr/bin/update.py

 

 

 

 

posted @ 2017-12-27 18:45  听风。  阅读(1754)  评论(0编辑  收藏  举报