I like to add the following command to my projects:
myproject/management/commands/run-script.py :
from django.core.management.base import BaseCommand, CommandError import imp import sys class Command(BaseCommand): help = """Run a non-django script with django settings.""" args = "<path_to_script.py> [<script_args>...]" def handle(self, *args, **options): if len(args) == 0: raise CommandError("Path to script to run is required") sys.argv = list(args) imp.load_source("__main__", args[0])
Then I can run my own scripts, for example:
./manage.py run-script /path/to/myscript.py --opt=value arg1 arg2
RΓ©gis B. Aug 17 '15 at 14:12 2015-08-17 14:12
source share