Sunday, May 29, 2011

Using Django functionalities in a stand-alone application

1. Set django file

2. Run syncdb to create DB tables
python syncdb

3. Create a shell script to set environment variables (NOTE : setting required variables to run django somehow cannot be done by python.)

export PYTHONPATH=$PYTHONPATH:/home/djangoprojects
export DJANGO_SETTINGS_MODULE="legacytest.settings"

python ./

4. Create a python file with django functions.

from newapp.models import *

# Pull all data from old DB
aa = Aa.objects.all()