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:

import sys, os
sys.path = [‘/home/mylogin/webapps/mysite, ‘/home/mylogin/webapps/mysite/lib/python2.5’] + sys.path
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘mysite.settings’