Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save djwesleyborges/886b9232cb389e13613a723e9a44c3fc to your computer and use it in GitHub Desktop.
Save djwesleyborges/886b9232cb389e13613a723e9a44c3fc to your computer and use it in GitHub Desktop.
Run cron task in your Django environment
#!/home/andre/.virtualenvs/myproject/bin/python
import os
import sys
DEBUG = False
#DEBUG = True
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# config o path da aplicacao
if DEBUG:
#set path to debug env
else:
PATH = [BASE_DIR,
os.path.join(BASE_DIR, 'vendor'),
os.path.join(BASE_DIR, 'scripts'),
#add others
]
for p in PATH:
if p not in sys.path:
sys.path.append(p)
#point to your settings file
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings_local' if DEBUG else 'config.settings'
import django
django.setup()
from myproject.models import SomeModel
#do whatever you want
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment