Answer the question
In order to leave comments, you need to log in
How to use Django models in your scripts?
Is it possible to somehow access Django models from third-party scripts?
Let's say I have a Card model with a title field
And I want to receive Card.objects.filter(title='Test') from a script on the same server. In this case, the script will simply spin in the background, i.e. called from outside django
Answer the question
In order to leave comments, you need to log in
In general, they answered from above. You can use commands. It's cool and comfortable. There is a battery for cron.
And if this is a completely external script or something project-site, but related, for example, some kind of chat or bot, then you need to import the django environment and it's better that it spins in the virtual environment of the project.
The import itself looks something like this:
import sys, os
import django
sys.path.append('/path/to/settings/py/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
django.setup()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question