0

According to this [article][1], I made the Command class.

myapp/management/commands/mycommand.py

class Command(BaseCommand):
    def command_test(self):
        print("test command_test")

Now I want to call this command_test from views.py like this below...

Is it possible??

in myapp/views.py

def index(request):
    Command.command_test()
whitebear
  • 11,200
  • 24
  • 114
  • 237
  • 1
    It is possible, but it is bad idea. Better move code, common between management command and views to some common.py file as simple function and use it in both cases. – LinnTroll Jan 22 '20 at 08:52
  • I see. thank you it's quite clear. I will make `service` or `library` (how can I call in django??), and use from both `views.py` and `command` – whitebear Jan 22 '20 at 09:00

0 Answers0