backends.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:django-mako 作者: ahmedaljazzar 项目源码 文件源码
def render(self, context=None, request=None):
        """
        Render the template with a given context. Here we're adding
        some context variables that are required for all templates in
        the system like the statix url and the CSRF tokens, etc.

        :param context: It must be a dict if provided
        :param request: It must be a django.http.HttpRequest if provided
        :return: A rendered template
        """
        if context is None:
            context = {}

        if request is not None:
            # As Django doesn't have a global request object,
            # it's useful to put it in the context.
            context['request'] = request
            # Passing the CSRF token is mandatory.
            context['csrf_input'] = csrf_input_lazy(request)
            context['csrf_token'] = csrf_token_lazy(request)

            context['static'] = static
            context['url'] = reverse

        return self.template.render(**context)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号