From a3e783fe11dd25bbf84bfb6201186566ed473506 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 8 Jan 2015 15:03:43 +0100 Subject: Deprecated passing a Context to a generic Template.render. A deprecation path is required because the return type of django.template.loader.get_template changed during the multiple template engines refactor. test_csrf_token_in_404 was incorrect: it tested the case when the hardcoded template was rendered, and that template doesn't depend on the CSRF token. This commit makes it test the case when a custom template is rendered. --- docs/internals/deprecation.txt | 6 ++++++ docs/ref/templates/upgrading.txt | 2 ++ docs/releases/1.8.txt | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) (limited to 'docs') diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index fe392cff97..e9161e7254 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -108,6 +108,12 @@ details on these changes. * The backwards compatibility alias ``django.template.loader.BaseLoader`` will be removed. +* Django template objects returned by + :func:`~django.template.loader.get_template` and + :func:`~django.template.loader.select_template` won't accept a + :class:`~django.template.Context` in their + :meth:`~django.template.backends.base.Template.render()` method anymore. + * The ``current_app`` parameter for the following function and classes will be removed: diff --git a/docs/ref/templates/upgrading.txt b/docs/ref/templates/upgrading.txt index ca336e016d..c7b07464b0 100644 --- a/docs/ref/templates/upgrading.txt +++ b/docs/ref/templates/upgrading.txt @@ -95,6 +95,8 @@ entire :setting:`TEMPLATES` setting instead. :mod:`django.template.loader` ============================= +.. _get_template-upgrade-django-18: + :func:`~django.template.loader.get_template` and :func:`~django.template.loader.select_template` ------------------------------------------------------------------------------------------------ diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 122064971c..4c3b398cd1 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -1380,6 +1380,23 @@ to construct the "view on site" URL. This URL is now accessible using the sure to provide a default value for the ``form_class`` argument since it's now optional. +Rendering templates loaded by :func:`~django.template.loader.get_template()` with a :class:`~django.template.Context` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The return type of :func:`~django.template.loader.get_template()` has changed +in Django 1.8: instead of a :class:`django.template.Template`, it returns a +``Template`` instance whose exact type depends on which backend loaded it. + +Both classes provide a ``render()`` method, however, the former takes a +:class:`django.template.Context` as an argument while the latter expects a +:class:`dict`. This change is enforced through a deprecation path for Django +templates. + +Since it's easier to understand with examples, the :ref:`upgrade guide +` shows how to adapt affected code. + +All this also applies to :func:`~django.template.loader.select_template()`. + ``current_app`` argument of template-related APIs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.3