开发者

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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜