This site runs best with JavaScript enabled.

Django cron on Webfaction


How to adjust the python path to run Django scripts in cron

James Bennett addresses one of the most frequently asked questions in Django "How do I write a standalone script which makes use of Django components?"

That is what I needed to do. I'm still learning Python so I wasn't sure why the methods he described in his article didn't work for me. (OK, I have an idea, but for the fear of looking stupid I'm not going to try to explain it.)

I'm using Webfaction to host my site, so I turned to their forum for assistance and found this topic. Still, the examples didn't quite work for me either. Finally, I found a clue in my WSGI script. Adding the following lines to my python file is what I needed to get me going:

1import sys, os
2
3sys.path = ['/home/mylogin/webapps/mysite', '/home/mylogin/webapps/mysite/lib/python2.5'] + sys.path
4os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

Discuss on TwitterEdit post on GitHub

Share article
Dustin Davis

Dustin Davis is a software engineer, people manager, hacker, and entreprenuer. He loves to develop systems and automation. He lives with his wife and five kids in Utah.

Join the Newsletter



Dustin Davis