I want to dump data from db to file in view. But I have some problems. When I call command:
call_command('dumpdata')
I receive data on console, but I don`t know how to save it to file. Command
call_command('dumpdata > backup.json')
gives me in result
Unknown command: ‘dumpdata > backup.json’ error.
file = open(backup_name, 'w')
file.write(call_command('dumpdata'))
file.close()
also don`t work. Any ideas?
call_commanddoes not accept shell commands, only django admin ones.Instead use this: