以编程方式使用Django的loaddata [英] Programmatically using Django's loaddata

查看:138
本文介绍了以编程方式使用Django的loaddata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Django视图中调用相当于 manage.py loaddata 的文件。我想要指定从哪里载入数据,哪个应用程序加载到。

I'd like to call the equivalent of manage.py loaddata from a Django view. I'd like to be able to specify where to load the data from and which application to load it into.

任何想法?

推荐答案

每个 django-admin.py manage.py )命令,如文档,您可以从代码中调用:

Each django-admin.py (manage.py) command, as seen in the documentation, you can call from your code with:

from django.core.management import call_command

call_command('loaddata', 'myapp')

第一个参数是命令名称,所有其他位置参数与命令行位置参数相同,所有关键字参数是选项。

Where first param is the command name, all other position params are the same as command line position params and all keyword params are options.

这篇关于以编程方式使用Django的loaddata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆