1024programmer Java Programmatically sync database in Django – ProgrammaticallysyncthedbinDjango

Programmatically sync database in Django – ProgrammaticallysyncthedbinDjango

I’m trying to sync my db from a view, something like this:

I’m trying to sync my database from a view like this:

from django import http
 from django.core import management

 def syncdb(request):
     management.call_command('syncdb')
     return http.HttpResponse('Database synced.')
 

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?

The problem is that it will block the development server by asking for user input from the terminal. How can I prevent what is being asked of me via the ‘–noinput’ option?

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.

I have other ways to mark the user as superuser so no user input is required, but I really need to call syncdb (and flush) programmatically instead No need to log into the server via ssh. Any help is appreciated.

2 solutions

#1


20

management.call_command('syncdb', interactive=False)
 

#2


4

Works like this (at least with Django 1.1.):

Works like this (at least with Django 1.1.):

from django.core.management.commands import syncdb
 syncdb.Command().execute(noinput=True)
 

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/756934

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索