Sunday, May 29, 2011

Using Django functionalities in a stand-alone application

1. Set django settings.py file

2. Run syncdb to create DB tables
python manage.py 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 ./access_db.py



4. Create a python file with django functions.

from newapp.models import *

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

No comments: