Programmatically using Django's loaddata

前端 未结 1 1074
孤街浪徒
孤街浪徒 2021-01-30 20:23

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 loa

相关标签:
1条回答
  • 2021-01-30 21:02

    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.

    0 讨论(0)
提交回复
热议问题