本文整理汇总了Python中django.core.management.base.BaseCommand.stdout方法的典型用法代码示例。如果您正苦于以下问题:Python BaseCommand.stdout方法的具体用法?Python BaseCommand.stdout怎么用?Python BaseCommand.stdout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.management.base.BaseCommand
的用法示例。
在下文中一共展示了BaseCommand.stdout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_models
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import stdout [as 别名]
def validate_models(self):
import django
try:
django_setup = django.setup
except AttributeError:
pass
else:
django_setup()
s = io.StringIO()
try:
from django.core.management.validation import get_validation_errors
except ImportError:
from django.core.management.base import BaseCommand
cmd = BaseCommand()
try:
# since django 1.5
from django.core.management.base import OutputWrapper
cmd.stdout = OutputWrapper(sys.stdout)
cmd.stderr = OutputWrapper(sys.stderr)
except ImportError:
cmd.stdout, cmd.stderr = sys.stdout, sys.stderr
cmd.check()
else:
num_errors = get_validation_errors(s, None)
if num_errors:
raise RuntimeError(
'One or more Django models did not validate:\n{0}'.format(
s.getvalue()))
示例2: make_wsgi_application
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import stdout [as 别名]
def make_wsgi_application():
# validate models
s = StringIO()
import django
from django.core.management.base import BaseCommand
django.setup()
cmd = BaseCommand()
import sys
cmd.stdout, cmd.stderr = sys.stdout, sys.stderr
cmd.check()
translation.activate(settings.LANGUAGE_CODE)
if django14:
return get_internal_wsgi_application()
return WSGIHandler()
示例3: validate_models
# 需要导入模块: from django.core.management.base import BaseCommand [as 别名]
# 或者: from django.core.management.base.BaseCommand import stdout [as 别名]
def validate_models(self):
s = io.StringIO()
try:
from django.core.management.validation import get_validation_errors
except ImportError:
import django
from django.core.management.base import BaseCommand
django.setup()
cmd = BaseCommand()
cmd.stdout, cmd.stderr = sys.stdout, sys.stderr
cmd.check()
else:
num_errors = get_validation_errors(s, None)
if num_errors:
raise RuntimeError(
'One or more Django models did not validate:\n{0}'.format(
s.getvalue()))