How To Run Python Script From Django

In this article we''ll show you how to run python script from Django shell,

FIrst you need to install django module

 pip install django-extensions

for more details about django-extensions visit

Then create directory scripts and files __init__,py and <your script name>.py

mkdir scripts
touch scripts/

touch scripts/


In this example I will run python script called , in that script write something like this :

from  mydatabase.models import Products

def run():
    # Get all products
    all_products = Products.objects.all()
    print all_products

under INSTALLED_APS in add



you can run script with command :

python runscript myscript Jan. 17, 2015, 4:09 a.m.