|
from time to time, your going to want to be really cool and be able to run commands in shell/command prompt from your gui... especially if your lazy like me and cba going into shell every time you need something doing.
to do this we use import subprocess.
Now we are going to use subprocess to call either manage.py or django-admin.py command's... hell you can even throw in your custom commands too.
The call function within subprocess takes one argument which we will split into an array to give the correct command.
subprocess.call(['commandfile', 'command'])
below is an example using syncdb from manage.py
import subprocess
def comm_syncdb(request): result = subprocess.call(['manage.py','syncdb'])
you can then call the result varible to print any response from shell.
i know this is a random and small tutorial but it may help someone lol.
|
|
|
|