[Answered ]-Receiving error: "TypeError: can only concatenate list (not "tuple") to list"

1đź‘Ť

âś…

() is an empty tuple whereas [] represents an empty list.

Since global_settings.TEMPLATE_CONTEXT_PROCESSORS is a list type, you should only concatenate that to another list:

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + []

1đź‘Ť

Example 1

>>> type(())
<type 'tuple'>

Example 2

>>> [1,2,3] + ()
TypeError: can only concatenate list (not "tuple") to list

On the last line of your example code, you’re adding (), which is , by the first example 1, the literal for an empty tuple. By your error and example 2, i can assume that global_settings.TEMPLATE_CONTEXT_PROCESSORS is a list, and you are trying to “list + tuple”, which is incompatible to __add__ and raises that exception.

Try changing the last line to:

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS

or, if by some unknown reason, you really need to add something…

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + []
👤Diogo Martins

Leave a comment