How to include the default TEMPLATE_CONTEXT_PROCESSORS in the new TEMPLATES setting in Django 1.10

2024/9/29 7:16:01

I'm upgrading a project to Django 1.10 and it has code like the following:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCPTEMPLATE_CONTEXT_PROCESSORS = TCP + ('django.template.context_processors.debug','django.template.context_processors.i18n','django.template.context_processors.media','django.template.context_processors.static','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages','django.template.context_processors.request',
)

As far as I can tell this was a common pattern when using previous versions of Django to ensure that the default context processors.

In Django 1.10 TEMPLATE_CONTEXT_PROCESSORS was removed in favour of the TEMPLATES setting which should now be defined something like this:

TEMPLATES = [{...,'OPTIONS': {'context_processors': ['django.template.context_processors.debug',...],},},
]

How should the TEMPLATES setting be defined to properly match the behaviour of the first code sample, i.e. ensuring that the default context processors are always included? Should I just manually include whatever was in django.conf.global_settings before? Does Django 1.10 have defaults defined anywhere? Are there any new context processors which should probably be included by default?

Answer

The question is "How should the TEMPLATES setting be defined to properly match the behaviour of the first code sample, i.e. ensuring that the default context processors are always included? "

My answer, in a similar situation, was to make a dummy directory and run 'django-admin startproject foo' in it. Then I examined foo/foo/settings.py to see the generated value of TEMPLATES.

This might not answer every question about how TEMPLATES should be set. But it does answer your question, about the default contents of TEMPLATES.

https://en.xdnf.cn/q/71243.html

Related Q&A

Selecting best range of values from histogram curve

Scenario :I am trying to track two different colored objects. At the beginning, user is prompted to hold the first colored object (say, may be a RED) at a particular position in front of camera (marked…

dash_bootstrap_components installed succesfully but no recognised

I have my dash working perfectly. I have installed dash_bootstrap_components to give style to my dash. I wrote pip install dash-bootstrap-components and was perfectly installed. But when I run the app,…

Efficient updates of image plots in Bokeh for interactive visualization

Im trying to create a smooth interactive visualization of different slices of a muldimensional array using Bokeh. The data in the slices changes according to the user interaction and thus has to be upd…

AttributeError: module cv2.cv2 has no attribute TrackerMOSSE_create

As the Dans suggestion, i tried to edit this post Error occurred at setting up MOOSE tracker, I also dont know why this error happened because i installed the Opencv-contrib-python==4.5.1.48.However,af…

Python, Error audio Recording in 16000Hz using Pyaudio

I use Python 2.7.3, Mac OS 10.8.2 and Xcode 4.5.1I am trying to record sound using PyAudio following the instructions in http://people.csail.mit.edu/hubert/pyaudio/and using the program ""&qu…

FastAPI passing json in get request via TestClient

Im try to test the api I wrote with Fastapi. I have the following method in my router : @app.get(/webrecord/check_if_object_exist) async def check_if_object_exist(payload: WebRecord) -> bool:key = g…

Python TDD directory structure

Is there a particular directory structure used for TDD in Python?Tutorials talk about the content of the tests, but not where to place themFrom poking around Python Koans, suspect its something like:/…

Pillow was built without XCB support

Im working on a program that uses ImageGrab in Pillow. I am getting the error mentioned in the title. I notice in the documentation that it says the generic pip install Pillow doesnt come with libxcb. …

Set equal aspect in plot with colorbar

I need to generate a plot with equal aspect in both axis and a colorbar to the right. Ive tried setting aspect=auto, aspect=1, and aspect=equal with no good results. See below for examples and the MWE.…

How to emit dataChanged in PyQt5

The code below breaks on self.emit line. It works fine in PyQt4. How to fix this code so it works in PyQt5?from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import QObject, pyqtSignalclass …