Answer the question
In order to leave comments, you need to log in
How to connect python scripts to django and use its models?
I have several python scripts. Scripts have classes, functions, and all this is scattered across several files.
What is the correct way to use django models in such scripts?
In addition, I will need to hang these scripts on cron. Where is the right place to store them?
I know that there are two ways:
1. Connect django with a direct call:
import os, sys
import django
sys.path.append("...")
#sys.path.append(os.path.realpath(__file__))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
django.setup()
Answer the question
In order to leave comments, you need to log in
Django has some pretty specific code organization requirements. It is better to stick to the structure that is described in the documentation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question