| | 361 | |
|---|
| | 362 | Loader types |
|---|
| | 363 | ~~~~~~~~~~~~ |
|---|
| | 364 | |
|---|
| | 365 | By default, Django uses a filesystem-based template loader, but Django comes |
|---|
| | 366 | with a few other template loaders. They're disabled by default, but you can |
|---|
| | 367 | activate them by editing your ``TEMPLATE_LOADERS`` setting. |
|---|
| | 368 | ``TEMPLATE_LOADERS`` should be a tuple of strings, where each string represents |
|---|
| | 369 | a template loader. Here are the built-in template loaders: |
|---|
| | 370 | |
|---|
| | 371 | ``django.core.template.loaders.filesystem.load_template_source`` |
|---|
| | 372 | Loads templates from the filesystem, according to ``TEMPLATE_DIRS``. |
|---|
| | 373 | |
|---|
| | 374 | ``django.core.template.loaders.app_directories.load_template_source`` |
|---|
| | 375 | Loads templates from Django apps on the filesystem. For each app in |
|---|
| | 376 | ``INSTALLED_APPS``, the loader looks for a ``templates`` subdirectory. If |
|---|
| | 377 | the directory exists, Django looks for templates in there. |
|---|
| | 378 | |
|---|
| | 379 | This means you can store templates with your individual apps. This also |
|---|
| | 380 | makes it easy to distribute Django apps with default templates. |
|---|
| | 381 | |
|---|
| | 382 | For example, for this setting:: |
|---|
| | 383 | |
|---|
| | 384 | INSTALLED_APPS = ('myproject.polls', 'myproject.music') |
|---|
| | 385 | |
|---|
| | 386 | ...then ``get_template("foo")`` will look for templates in these |
|---|
| | 387 | directories, in this order: |
|---|
| | 388 | |
|---|
| | 389 | * ``/path/to/myproject/polls/templates/foo.html`` |
|---|
| | 390 | * ``/path/to/myproject/music/templates/music.html`` |
|---|
| | 391 | |
|---|
| | 392 | Note that the loader performs an optimization when it is first imported: |
|---|
| | 393 | It caches a list of which ``INSTALLED_APPS`` packages have a ``templates`` |
|---|
| | 394 | subdirectory. |
|---|
| | 395 | |
|---|
| | 396 | ``django.core.template.loaders.eggs.load_template_source`` |
|---|
| | 397 | Just like ``app_directories`` above, but it loads templates from Python |
|---|
| | 398 | eggs rather than from the filesystem. |
|---|
| | 399 | |
|---|
| | 400 | Django uses the template loaders in order according to the ``TEMPLATE_LOADERS`` |
|---|
| | 401 | setting. It uses each loader until a loader finds a match. |
|---|