If you want to create a Django Management Command (and not a function), create a new python file under
"Your-Django-App -> management -> commands -> your_custom_command.py"
Then, create a Command class. You can define here where you want to download your files. Example:
class Command(BaseCommand):
media_folder = os.getcwd() + '/media/'
private_folder = os.getcwd() + '/private/'
def handle(self, *args, **options):
# insert your code here
You can execute this command from the terminal:
python manage.py your_custom_command
Or you can execute it from your code. More information here on Django documentation: https://docs.djangoproject.com/en/1.11/ref/django-admin/#running-management-commands-from-your-code
Here you can read more about management commands:
https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/