Sobes.tech
Junior — Middle

Have you created custom management commands in Django to extend functionality via command line?

sobes.tech AI

Answer from AI

Yes, in Django, you can create custom management commands to extend functionality via the command line. To do this:

  1. Create a folder named management/commands in your app.
  2. Inside it, create a file with the name of your command, for example, mycommand.py.
  3. In this file, define a class inheriting from BaseCommand.
  4. Override the handle(self, *args, **options) method, where you implement the command logic.

Here's an example of a simple command:

from django.core.management.base import BaseCommand

class Command(BaseCommand):
    help = 'Example of a custom command'

    def handle(self, *args, **options):
        self.stdout.write('Command executed successfully!')

After that, you can run the command using python manage.py mycommand.