I'm getting started with Django on Windows. And the tutorial http://docs.djangoproject.com/en/dev/intro/tutorial01/ has me running "python manage.py <command>" from a command promt all the time.

But I'm wondering: Couldn't I run the manage.py commands from PythonWin or IDLE?

Maybe something along these lines (prompt when running, after exit manage() command). It does bring up the terminal window.

# run_me.py
import os
def manage():
    s=' '
    print 'Finnish manage command by entering empty line.'
    while s<>'':
        os.chdir('d:\\Python Projects\mysite')
        s=raw_input('#')
        if s: os.system('python manage.py '+s)
manage()

or you can use instead of os.system this Command from
http://www.daniweb.com/forums/post1187140.html#post1187140

class Command(object):
    """Run a command and capture it's output string, error string and exit status"""

    def __init__(self, command):
        self.command = command 

    def run(self, shell=True):
        import subprocess as sp
        process = sp.Popen(self.command, shell = shell, stdout = sp.PIPE, stderr = sp.PIPE)
        self.pid = process.pid
        self.output, self.error = process.communicate()
        self.failed = process.returncode
        return self

    @property
    def returncode(self):
        return self.failed

On Windows OS this behaves like double-clicking on the Python code file name ...

import os
os.startfile("manage.py")

I was thinking of something along the lines of Oracles ability to run SQL scripts from the SQL*Plus command line, like so:

SQL> start  script.sql  param1  param2

I guess what I'm asking is, if the Python command interpreter (and thereby PythonWin and IDLE) can do this:

>>> manage.py  syncdb

The more primitive solution:

# run_me.py
import os
def manage(s): os.system('python manage.py '+s)

## let's keep it working not only in windows

manage('syncdb')
## after running this file you can use manage-command from IDLE command window
## but output goes to separate terminal window
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.