Unknown command dumpdata
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_command
does not accept shell commands, only django admin ones.
Instead use this:
import sys
sys.stdout = open('backup.json', 'w')
call_command('dumpdata')
精彩评论