Skip to content

Instantly share code, notes, and snippets.

@clint74
Created August 29, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save clint74/1672b5a45575660c1debed34356f46f8 to your computer and use it in GitHub Desktop.
Save clint74/1672b5a45575660c1debed34356f46f8 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