Where is template context processor in Django 1.5?

烈酒焚心 提交于 2019-11-28 08:11:52

In your settings.py you can define TEMPLATE_CONTEXT_PROCESSORS setting.

However, django has defined default values for this setting which is

("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages")

If you want to add your custom template context processor which maintaining the default processors, you can do following in settings.py

import django.conf.global_settings as DEFAULT_SETTINGS

TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
    'custom_context_processors.my_context_processor',
)

Refer TEMPLATE_CONTEXT_PROCESSORS doc.

You can check what context processors your app is using by jumping into the django python shell and importing your settings.

$ manage.py shell
> from django.conf import settings
> settings.TEMPLATE_CONTEXT_PROCESSORS

If you have not overridden them then the defaults should be rendered.

On static files, check your STATICFILES_DIRS which is where django's development server will look to serve static assets: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATICFILES_DIRS.

I use this in my settings.py:

from os.path import join, abspath
PROJECT_ROOT = abspath(join(dirname(__file__), '..', '..'))
STATICFILES_DIRS = [join(PROJECT_ROOT, 'public'), ]

This won't be the same for you as it will depend on how you layout your project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!