$ python manage.py shell -c 'from django.core.management import utils; print(utils.get_random_secret_key())'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# generate_secret.py
from django.core.management import utils
print(utils.get_random_secret_key())
$ python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'