Skip to content

Commit ee148df

Browse files
author
guibog
committed
Add Templating section in scenario/web
1 parent 911d829 commit ee148df

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/scenarios/web.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Web Applications
33
================
44

5+
As a powerful scripting language adapted to both fast prototyping
6+
and bigger projects, Python is widely used in Web applications
7+
development.
58

69
Context
710
:::::::
@@ -203,6 +206,44 @@ Gondor publishes guides to deploying `Django projects
203206
<https://gondor.io/support/setting-up-pinax/>`_ on their platform.
204207

205208

209+
Templating
210+
::::::::::
211+
212+
Most WSGI applications are responding to HTTP requests to serve
213+
content in HTML or other markup languages. Instead of generating directly
214+
textual content from Python, the concept of separation of concerns
215+
advise us to use templates. A template engine manage a suite of
216+
template files, with a system of hierarchy and inclusion to
217+
avoid unnecessary repetition, and is in charge of rendering
218+
(generating) the actual content, filling the static content
219+
of the templates with the dynamic content generated by the
220+
application.
221+
222+
As template files are
223+
sometime written by designers or front-end developpers,
224+
it can be difficult to handle increasing complexity.
225+
226+
Some general good pratices apply to the part of the
227+
application passing dynamic content to the template engine,
228+
and to the templates themselves.
229+
230+
- Template files should be passed only the dynamic
231+
content that is needed for rendering the template. Avoid
232+
to be tempted to pass additional content "just in case":
233+
it is easier to add some missing variable when needed than to remove
234+
a likely unused variable later.
235+
236+
- Many template engine allow for complex statements
237+
or assignments in the template itself, and many
238+
allow some Python code to be evaluated in the
239+
templates. This convenience can lead to uncontrolled
240+
increase in complexity, and often harder to find bugs.
241+
242+
- It is often possible or necessary to mix javascript templates with
243+
HTML templates. A sane approach to this design is to isolate
244+
the parts where the HTML template passes some variable content
245+
to the javascript code.
246+
206247
.. rubric:: References
207248

208249
.. [1] `The mod_python project is now officially dead <http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html>`_

0 commit comments

Comments
 (0)