本文介绍了以编程方式同步Django中的db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从视图中同步我的数据库,如下所示:
I'm trying to sync my db from a view, something like this:
from django import http
from django.core import management
def syncdb(request):
management.call_command('syncdb')
return http.HttpResponse('Database synced.')
问题是,它将通过从终端请求用户输入来阻止dev服务器。如何传递' - noinput'
选项以防止问我什么?
The issue is, it will block the dev server by asking for user input from the terminal. How can I pass it the '--noinput'
option to prevent asking me anything?
我有其他方法将用户标记为超级用户,因此不需要用户输入,但我真的需要调用 syncdb
(和 flush
)以编程方式,不通过ssh登录到服务器。任何帮助都不胜感激。
I have other ways of marking users as super-user, so there's no need for the user input, but I really need to call syncdb
(and flush
) programmatically, without logging on to the server via ssh. Any help is appreciated.
推荐答案
management.call_command('syncdb', interactive=False)
这篇关于以编程方式同步Django中的db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!