lino.management.commands.run

run

Execute a standalone Python script after having set up the Django environment.

manage.py run myscript.py is almost the same as redirecting stdin of Django's shell command (i.e. doing manage.py shell < myscript.py), but with the possibility of using command line arguments.

For example if you have a file myscript.py with the following content...

import sys
from myapp.models import Partner
print Partner.objects.get(pk=sys.args[1])

... then you can run this script using:

$ python manage.py run myscript.py 101
Bäckerei Ausdemwald

This command modifies sys.args, __file__ and __name__ so that the invoked script sees them as if it had been called directly.

It is similar to the runscript command which comes with django-extensions.

This is yet another answer to the frequently asked Django question about how to run standalone Django scripts ([1], [2]).

(This module's source code is available here.)

Classes

Command([stdout, stderr, no_color, force_color])