在 Django 的 View 中调用 syncdb

完全吃不消 SAE 的 MySQL 各种限制了,无数次地清空数据库 -> 重新初始化 -> 导入 SQL 文件。

为什么不能在 Django 中建立好 Model 后,直接从 Django 的 View 里 syncdb 呢。

from django.http import HttpResponse

def syncdb(request):
from django.core.management import call_command
from cStringIO import StringIO
import sys
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
mystdout.write(&apos&ltpre&gt&apos)
call_command(&apossyncdb&apos)
mystdout.write(&apos&lt/pre&gt&apos)
sys.stdout = old_stdout
mystdout.seek(0)
return HttpResponse(mystdout.read())

什么时候再把 South 整合进去就完美啦~~~ -)

版权所有丨转载请注明出处:https://kxq.io/archives/在django的view中调用syncdb