How to run an arbitrary script in the context of the Django project?

23 Sep · by Tim Kamanin · 1 min read

The easiest way to do this is to set up your script as a subcommand. Here's how to do that:

from import NoArgsCommand, make_option

class Command(NoArgsCommand):

    help = "Whatever you want to print here"

    option_list = NoArgsCommand.option_list + (
        make_option('--verbose', action='store_true'),

    def handle_noargs(self, **options):
        ... call your script here ...

Save it as management/commands/ and now you can call your script with ./ yourcommand. Simple!

Example taken from:


Required for comment verification