Base template for all apps in Django

前端 未结 3 1214
渐次进展
渐次进展 2021-02-07 02:01

I have a project with 2 apps

project/
    blog/
        templates/
            index.html
    polls/
        templates/
            index.html
    project/
              


        
3条回答
  •  感情败类
    2021-02-07 02:39

    For Django versions above 1.8 the upgrade doc suggests the vanilla settings (for most non-advanced django tangoers like me) be added to your settings.py:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [(os.path.join(BASE_DIR, 'my_Templates_Directory')),],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
                    # list if you haven't customized them:
                    'django.contrib.auth.context_processors.auth',
                    'django.template.context_processors.debug',
                    'django.template.context_processors.i18n',
                    'django.template.context_processors.media',
                    'django.template.context_processors.static',
                    'django.template.context_processors.tz',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]
    

    Both BACKEND and OPTIONS were required, otherwise I had errors relating to 'INVALID BACKEND' and 'django.contrib.auth.context_processors.auth' must be in TEMPLATES'.

提交回复
热议问题