以编程方式使用 Django 的 loaddata

发布于 2024-07-21 21:19:07 字数 111 浏览 3 评论 0原文

我想从 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.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

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

from django.core.management import call_command

call_command('loaddata', 'myapp')

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文