vZ10
vZ10

Reputation: 2676

Can't run custom commands in Django 1.5.1

I've read the tutorial and did every step from it.

I've add management/commands folder to my project folder enter image description here

I've made python file for custom command

from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):

def handle(self, **options):
    print 'Hello world!'

After that I started my command

enter image description here

I've read all questions about this problem, but I didn't find any solution for me. And I don't understand where I can get

_ init _ .py

files

Upvotes: 0

Views: 178

Answers (3)

Hasan Ramezani
Hasan Ramezani

Reputation: 5194

Follow this step for corrections;

1-create an empty file with name __init__.py in management directory.

2-create an empty file with name __init__.py in commands directory.

3-change your add.py like this:

from django.core.management.base import BaseCommand
class Command(BaseCommand):
    def handle(self, *args, **options):
        print 'Hello world!'

Now you can run management command by:

./manage.py add

Upvotes: 1

J. Ghyllebert
J. Ghyllebert

Reputation: 2027

You're missing the __init__.py file in both management and commands directory.

You can create such a file using touch __init__.py in the terminal

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599490

You don't "get" __init__.py files: you create empty ones. That's the reason your command is not found; you need those in both the management and the commands folders.

This is true for anything in Python; you always need an __init__.py to import a module within a subdirectory.

Upvotes: 1

Related Questions