Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
pyramid.pdf
Скачиваний:
11
Добавлен:
24.03.2015
Размер:
3.82 Mб
Скачать

11.10. AUTOMATICALLY RELOADING TEMPLATES

mako.directories = mypackage:templates

This lets the Mako templating system know that it should look for templates in the templates subdirectory of the mypackage Python package. See Mako Template Render Settings for more information about the mako.directories setting and other Mako-related settings that can be placed into the application’s ini file.

11.9.1 A Sample Mako Template

Here’s what a simple Mako template used under Pyramid might look like:

1

2

3

4

5

6

7

8

9

10

11

<html>

<head>

<title>${project} Application</title>

</head>

<body>

<h1 class="title">Welcome to <code>${project}</code>, an application generated by the <a href="http://docs.pylonsproject.org/projects/pyramid/current/"

>pyramid</a> web application framework.</h1>

</body>

</html>

This template doesn’t use any advanced features of Mako, only the ${} replacement syntax for names that are passed in as renderer globals. See the the Mako documentation to use more advanced features.

11.10 Automatically Reloading Templates

It’s often convenient to see changes you make to a template file appear immediately without needing to restart the application process. Pyramid allows you to configure your application development environment so that a change to a template will be automatically detected, and the template will be reloaded on the next rendering.

latex-warning.png

Auto-template-reload behavior is not recommended for production sites as it slows rendering slightly; it’s usually only desirable during development.

133

11. TEMPLATES

In order to turn on automatic reloading of templates, you can use an environment variable, or a configuration file setting.

To use an environment variable, start your application under a shell using the PYRAMID_RELOAD_TEMPLATES operating system environment variable set to 1, For example:

$ PYRAMID_RELOAD_TEMPLATES=1 bin/pserve myproject.ini

To use a setting in the application .ini file for the same purpose, set the pyramid.reload_templates key to true within the application’s configuration section, e.g.:

1

2

3

[app:main]

use = egg:MyProject pyramid.reload_templates = true

11.11 Available Add-On Template System Bindings

Jinja2 template bindings are available for Pyramid in the pyramid_jinja2 package. You can get the latest release of this package from the Python package index (pypi).

134

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]