需要在檔頭設定
myfile.py
import sys, os
sys.path.append('/YOUR/PROJECT/PATH')
os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings'
from django.core.management import setup_environ
# here is your code
sys.path.append('/YOUR/PROJECT/PATH')
os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings'
from django.core.management import setup_environ
# here is your code
接著在主機中專案目錄執行
python /myfilepath/myfile.py
排程的話,編輯crontable
crontab -e
*/30 * * * * python /fullpath/myfile.py
0 留言