开发者

Run custom admin command from view

开发者 https://www.devze.com 2023-03-10 11:54 出处:网络
I have a custom admin command that emails out reports开发者_如何学Python. It normally runs from a cron job. What I would like to do is add a button to my web app that when clicked will cause the the a

I have a custom admin command that emails out reports开发者_如何学Python. It normally runs from a cron job. What I would like to do is add a button to my web app that when clicked will cause the the admin command to run there and then rather than wait for the cron job to call it. How do I do this? Do I have to call out to a command line such as

python manage.py myadmincmd 

or can I invoke the code from within a view? It seems it would be cleaner if I could do this from within a view without needing to break out to the command line.


You can use call_command:

from django.core.management import call_command
call_command('myadmincmd')
0

精彩评论

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

关注公众号