The relevant part or django.template.backends.base.py looks like this:
class BaseEngine(object):
# Core methods: engines have to provide their own implementation
# (except for from_string which is optional).
def __init__(self, params):
"""
Initializes the template engine.
Receives the configuration settings as a dict.
"""
params = params.copy()
self.name = params.pop('NAME')
self.dirs = list(params.pop('DIRS'))
self.app_dirs = bool(params.pop('APP_DIRS'))
if params:
raise ImproperlyConfigured(
"Unknown parameters: {}".format(", ".join(params)))
The dictionary params
in def __init__(self, params):
will be copied to a new dictionary params = params.copy()
. It just uses the same name. Therefore, the old object cannot be accessed any more via this name. In the next steps the new local dictionary is modified but the original one stays unchanged.
Doing self.params = params
, instead of params = params.copy()
would have a very different effect. In this case self.params
would be just a second name for the object behind params
. Since it is a dictionary and mutable, all changes to self.params
would effect params
. params.pop('NAME')
removes the key NAME'
from the dictionary. Actually, there is a check that it is empty: params.pop('NAME')
.