Reputation: 1027
Is it possible to use Django in a python script?
I think I saw something about it in the past, but I can't find any reference to it now. So, basically, I want to build a python script and access Django ORM.
Thanks for any help
Upvotes: 0
Views: 446
Reputation: 33335
import sys
import os
sys.path.insert(0, 'root directory of my project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django
django.setup()
from myapp.models import MyModel
# now you can access MyModel objects just as if you were in a django view
Upvotes: 2