Running a Python script outside of Django

Viewed 27141

I have a script which uses the Django ORM features, amongst other external libraries, that I want to run outside of Django (that is, executed from the command-line).

Edit: At the moment, I can launch it by navigating to a URL...

How do I setup the environment for this?

7 Answers

a simple way:

$ python manage.py shell -c 'import runpy; runpy.run_path("scripts/script_to_run.py")'

where scripts/script_to_run.py is the desired script to run!

you can create a bash script called "runscript.py":

#!/bin/bash
python manage.py shell -c 'import runpy; runpy.run_path("'$1'")'

then run:

$ runscript.py scripts/script_to_run.py
Related