update()方法到底做了什么(假设if条件给出了一个空字典)?

2022-01-18 23:49:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我不明白dict\u字典对email\u ctx字典做了什么,它是不是空的,它是否覆盖了一些数据

class EmailTemplateContext(Context):
    @staticmethod
    def make_link(path):
        return settings.MAILING_LIST_LINK_DOMAIN + path

    def __init__(self, subscriber, dict_=None, **kwargs):
        if dict_ is None:
            dict_ = {}

        email_ctx = self.common_context(subscriber)
        email_ctx.update(dict_)
        super().__init__(email_ctx, **kwargs)

    def common_context(self, subscriber):
        subscriber_pk_kwargs = {'pk': subscriber.id}
        unsubscribe_path = reverse(
            'mailing_list:unsubscribe',
            kwargs=subscriber_pk_kwargs,
        )
        return {
            'subscriber':subscriber,
            'mailing_list': subscriber.mailing_list,
            'unsubscribe_link': self.make_link(unsubscribe_path),
        }