from random import choice

from django.core.management.base import BaseCommand

from django_extensions.management.utils import signalcommand


class Command(BaseCommand):
    help = "Generates a new SECRET_KEY that can be used in a project settings file."

    requires_system_checks = False

    @signalcommand
    def handle(self, *args, **options):
        return ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])

from random import choice

from django.core.management.base import BaseCommand
from django.core.management.utils import get_random_secret_key

from django_extensions.management.utils import signalcommand


class Command(BaseCommand):
    help = "Generates a new SECRET_KEY that can be used in a project settings file."

    requires_system_checks = False

    @signalcommand
    def handle(self, *args, **options):
        return get_random_secret_key()

Use same algo to generate SECRET_KEY as Django
Use same algo to generate SECRET_KEY as Django

Using random from standard library is not cryptographically secure.
  from random import choice
  
  from django.core.management.base import BaseCommand
+ from django.core.management.utils import get_random_secret_key
  
  from django_extensions.management.utils import signalcommand
  
  
  class Command(BaseCommand):
      help = "Generates a new SECRET_KEY that can be used in a project settings file."
  
      requires_system_checks = False
  
      @signalcommand
      def handle(self, *args, **options):
-         return ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
+         return get_random_secret_key()
  
Use same algo to generate SECRET_KEY as Django
## Code Before:
from random import choice

from django.core.management.base import BaseCommand

from django_extensions.management.utils import signalcommand


class Command(BaseCommand):
    help = "Generates a new SECRET_KEY that can be used in a project settings file."

    requires_system_checks = False

    @signalcommand
    def handle(self, *args, **options):
        return ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])

## Instruction:
Use same algo to generate SECRET_KEY as Django
## Code After:
from random import choice

from django.core.management.base import BaseCommand
from django.core.management.utils import get_random_secret_key

from django_extensions.management.utils import signalcommand


class Command(BaseCommand):
    help = "Generates a new SECRET_KEY that can be used in a project settings file."

    requires_system_checks = False

    @signalcommand
    def handle(self, *args, **options):
        return get_random_secret_key()
