Created
August 29, 2018 16:35
-
-
Save clint74/1672b5a45575660c1debed34356f46f8 to your computer and use it in GitHub Desktop.
Run cron task in your Django environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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