apps.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:django-boardinghouse 作者: schinckel 项目源码 文件源码
def check_context_processor_installed(app_configs=None, **kwargs):
    "Warn if our context processor is not installed."
    from django.conf import settings

    errors = []

    if hasattr(settings, 'TEMPLATES'):
        for i, engine in enumerate(settings.TEMPLATES):
            # We only check for the context processor if using the default django backend.
            if engine['BACKEND'] != 'django.template.backends.django.DjangoTemplates':
                continue
            if CONTEXT not in engine.get('OPTIONS', {}).get('context_processors', []):
                errors.append(Warning(
                    'Missing boardinghouse context processor',
                    hint="Add '{1}' to settings.TEMPLATES[{0}]"
                         "['OPTIONS']['context_processors']".format(i, CONTEXT),
                    id='boardinghouse.W001'
                ))
    elif hasattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS'):
        if CONTEXT not in settings.TEMPLATE_CONTEXT_PROCESSORS:
            errors.append(Warning(
                'Missing boardinghouse context processor',
                hint="Add '{0}' to settings.TEMPLATE_CONTEXT_PROCESSORS".format(CONTEXT),
                id='boardinghouse.W001'
            ))
    else:
        errors.append(Warning(
            'Missing boardinghouse context processor (no TEMPLATES defined)',
            hint="Configure settings.TEMPLATES and add '{0}'".format(CONTEXT),
            id='boardinghouse.W001',
        ))

    return errors
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号