Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
277fe2e8
Kaydet (Commit)
277fe2e8
authored
Eyl 03, 2016
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Eyl 03, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25788 -- Enabled the cached template loader if debug is False.
üst
2ced2f78
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
13 deletions
+55
-13
engine.py
django/template/engine.py
+2
-0
api.txt
docs/ref/templates/api.txt
+27
-11
1.11.txt
docs/releases/1.11.txt
+6
-0
test_django.py
tests/template_backends/test_django.py
+15
-0
tests.py
tests/template_loader/tests.py
+4
-1
test_loaders.py
tests/template_tests/test_loaders.py
+1
-1
No files found.
django/template/engine.py
Dosyayı görüntüle @
277fe2e8
...
@@ -27,6 +27,8 @@ class Engine(object):
...
@@ -27,6 +27,8 @@ class Engine(object):
loaders
=
[
'django.template.loaders.filesystem.Loader'
]
loaders
=
[
'django.template.loaders.filesystem.Loader'
]
if
app_dirs
:
if
app_dirs
:
loaders
+=
[
'django.template.loaders.app_directories.Loader'
]
loaders
+=
[
'django.template.loaders.app_directories.Loader'
]
if
not
debug
:
loaders
=
[(
'django.template.loaders.cached.Loader'
,
loaders
)]
else
:
else
:
if
app_dirs
:
if
app_dirs
:
raise
ImproperlyConfigured
(
raise
ImproperlyConfigured
(
...
...
docs/ref/templates/api.txt
Dosyayı görüntüle @
277fe2e8
...
@@ -103,8 +103,16 @@ what's passed by :class:`~django.template.backends.django.DjangoTemplates`.
...
@@ -103,8 +103,16 @@ what's passed by :class:`~django.template.backends.django.DjangoTemplates`.
* ``'django.template.loaders.app_directories.Loader'`` if and only if
* ``'django.template.loaders.app_directories.Loader'`` if and only if
``app_dirs`` is ``True``.
``app_dirs`` is ``True``.
If ``debug`` is ``False``, these loaders are wrapped in
:class:`django.template.loaders.cached.Loader`.
See :ref:`template-loaders` for details.
See :ref:`template-loaders` for details.
.. versionchanged:: 1.11
Enabling of the cached template loader when ``debug`` is ``False``
was added.
* ``string_if_invalid`` is the output, as a string, that the template
* ``string_if_invalid`` is the output, as a string, that the template
system should use for invalid (e.g. misspelled) variables.
system should use for invalid (e.g. misspelled) variables.
...
@@ -899,18 +907,22 @@ loaders that come with Django:
...
@@ -899,18 +907,22 @@ loaders that come with Django:
.. class:: cached.Loader
.. class:: cached.Loader
By default, the templating system will read and compile your templates every
By default (when :setting:`DEBUG` is ``True``), the template system reads
time they need to be rendered. While the Django templating system is quite
and compiles your templates every time they're rendered. While the Django
fast, the overhead from reading and compiling templates can add up.
template system is quite fast, the overhead from reading and compiling
templates can add up.
The cached template loader is a class-based loader that you configure with
You configure the cached template loader with a list of other loaders that
a list of other loaders that it should wrap. The wrapped loaders are used to
it should wrap. The wrapped loaders are used to locate unknown templates
locate unknown templates when they are first encountered. The cached loader
when they're first encountered. The cached loader then stores the compiled
then stores the compiled ``Template`` in memory. The cached ``Template``
``Template`` in memory. The cached ``Template`` instance is returned for
instance is returned for
subsequent requests to load the same template.
subsequent requests to load the same template.
For example, to enable template caching with the ``filesystem`` and
This loader is automatically enabled if :setting:`DEBUG` is ``False`` and
``app_directories`` template loaders you might use the following settings::
:setting:`OPTIONS['loaders'] <TEMPLATES-OPTIONS>` isn't specified.
You can also enable template caching with some custom template loaders
using settings like this::
TEMPLATES = [{
TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
...
@@ -920,6 +932,7 @@ loaders that come with Django:
...
@@ -920,6 +932,7 @@ loaders that come with Django:
('django.template.loaders.cached.Loader', [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.app_directories.Loader',
'path.to.custom.Loader',
]),
]),
],
],
},
},
...
@@ -934,7 +947,10 @@ loaders that come with Django:
...
@@ -934,7 +947,10 @@ loaders that come with Django:
information, see :ref:`template tag thread safety considerations
information, see :ref:`template tag thread safety considerations
<template_tag_thread_safety>`.
<template_tag_thread_safety>`.
This loader is disabled by default.
.. versionchanged:: 1.11
The automatic enabling of the cached template loader when ``debug`` is
``False`` was added.
``django.template.loaders.locmem.Loader``
``django.template.loaders.locmem.Loader``
...
...
docs/releases/1.11.txt
Dosyayı görüntüle @
277fe2e8
...
@@ -471,6 +471,12 @@ Miscellaneous
...
@@ -471,6 +471,12 @@ Miscellaneous
:class:`~django.core.serializers.json.DjangoJSONEncoder` (renamed in Django
:class:`~django.core.serializers.json.DjangoJSONEncoder` (renamed in Django
1.0) is removed.
1.0) is removed.
* The :class:`cached template loader <django.template.loaders.cached.Loader>`
is now enabled if :setting:`DEBUG` is ``False`` and
:setting:`OPTIONS['loaders'] <TEMPLATES-OPTIONS>` isn't specified. This could
be backwards-incompatible if you have some :ref:`template tags that aren't
thread safe <template_tag_thread_safety>`.
.. _deprecated-features-1.11:
.. _deprecated-features-1.11:
Features deprecated in 1.11
Features deprecated in 1.11
...
...
tests/template_backends/test_django.py
Dosyayı görüntüle @
277fe2e8
...
@@ -130,3 +130,18 @@ class DjangoTemplatesTests(TemplateStringsTests):
...
@@ -130,3 +130,18 @@ class DjangoTemplatesTests(TemplateStringsTests):
engines
[
'django'
]
.
from_string
(
'Hello, {{ name }}'
)
.
render
({
'name'
:
'Bob & Jim'
}),
engines
[
'django'
]
.
from_string
(
'Hello, {{ name }}'
)
.
render
({
'name'
:
'Bob & Jim'
}),
'Hello, Bob & Jim'
'Hello, Bob & Jim'
)
)
default_loaders
=
[
'django.template.loaders.filesystem.Loader'
,
'django.template.loaders.app_directories.Loader'
,
]
@override_settings
(
DEBUG
=
False
)
def
test_non_debug_default_template_loaders
(
self
):
engine
=
DjangoTemplates
({
'DIRS'
:
[],
'APP_DIRS'
:
True
,
'NAME'
:
'django'
,
'OPTIONS'
:
{}})
self
.
assertEqual
(
engine
.
engine
.
loaders
,
[(
'django.template.loaders.cached.Loader'
,
self
.
default_loaders
)])
@override_settings
(
DEBUG
=
True
)
def
test_debug_default_template_loaders
(
self
):
engine
=
DjangoTemplates
({
'DIRS'
:
[],
'APP_DIRS'
:
True
,
'NAME'
:
'django'
,
'OPTIONS'
:
{}})
self
.
assertEqual
(
engine
.
engine
.
loaders
,
self
.
default_loaders
)
tests/template_loader/tests.py
Dosyayı görüntüle @
277fe2e8
...
@@ -11,11 +11,14 @@ from django.test.client import RequestFactory
...
@@ -11,11 +11,14 @@ from django.test.client import RequestFactory
'APP_DIRS'
:
True
,
'APP_DIRS'
:
True
,
},
{
},
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'context_processors'
:
[
'context_processors'
:
[
'django.template.context_processors.request'
,
'django.template.context_processors.request'
,
],
],
'loaders'
:
[
'django.template.loaders.filesystem.Loader'
,
'django.template.loaders.app_directories.Loader'
,
]
},
},
}])
}])
class
TemplateLoaderTests
(
SimpleTestCase
):
class
TemplateLoaderTests
(
SimpleTestCase
):
...
...
tests/template_tests/test_loaders.py
Dosyayı görüntüle @
277fe2e8
...
@@ -279,7 +279,7 @@ class FileSystemLoaderTests(SimpleTestCase):
...
@@ -279,7 +279,7 @@ class FileSystemLoaderTests(SimpleTestCase):
@classmethod
@classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
cls
.
engine
=
Engine
(
dirs
=
[
TEMPLATE_DIR
])
cls
.
engine
=
Engine
(
dirs
=
[
TEMPLATE_DIR
]
,
loaders
=
[
'django.template.loaders.filesystem.Loader'
]
)
super
(
FileSystemLoaderTests
,
cls
)
.
setUpClass
()
super
(
FileSystemLoaderTests
,
cls
)
.
setUpClass
()
@contextmanager
@contextmanager
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment