Following the example of writing a custom django-admin command here, I've created the following custom command:
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
args = ''
help = 'Test command'
def handle(self, *args, **options):
self.stdout.write("Hello World!")
Surprisingly, I receive the following stack trace:
Traceback (most recent call last):
File "D:\My Documents\Dev\MyProject\svn\trunk\dj_project\manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python26\lib\site-packages\django\core\management\base.py", line 218, in execute
output = self.handle(*args, **options)
File "D:\My Documents\Dev\MyProject\svn\trunk\dj_project\..\dj_project\dj_app\management\commands\mytest.py", line 8, in handle
self.stdout.write("Hello World!")
AttributeError: 'Command' object has no attribute 'stdout'
How come? This is a very basic custom command that as far as I understand conforms to the example.
I'm using django 1.2.1