Django

Code

Changeset 893

Show
Ignore:
Timestamp:
10/16/05 22:00:18 (3 years ago)
Author:
adrian
Message:

Added 'Loader types' section to docs/templates_python.txt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/templates_python.txt

    r867 r893  
    288288".html" extension in a directory specified as a **template directory**. 
    289289 
    290 (The ".html" extension is just a required convention. It doesn't mean templates 
    291 can only contain HTML. They can contain whatever textual content you want.) 
     290If you don't like the requirement that templates have an ".html" extension, 
     291change your ``TEMPLATE_FILE_EXTENSION`` setting. It's set to ``".html"`` by 
     292default. 
     293 
     294Also, the .html extension doesn't mean templates can contain only HTML. They 
     295can contain whatever textual content you want. 
    292296 
    293297The TEMPLATE_DIRS setting 
     
    355359 
    356360    get_template("news/story_detail") 
     361 
     362Loader types 
     363~~~~~~~~~~~~ 
     364 
     365By default, Django uses a filesystem-based template loader, but Django comes 
     366with a few other template loaders. They're disabled by default, but you can 
     367activate them by editing your ``TEMPLATE_LOADERS`` setting. 
     368``TEMPLATE_LOADERS`` should be a tuple of strings, where each string represents 
     369a 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 
     400Django uses the template loaders in order according to the ``TEMPLATE_LOADERS`` 
     401setting. It uses each loader until a loader finds a match. 
    357402 
    358403Extending the template system