Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40459

Re: Embedding a for inside an html template for substitution

Date 2013-03-04 08:59 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Embedding a for inside an html template for substitution
References <1a5a68d8-a97e-4069-a860-c7737dd5a503@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2845.1362412789.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 03/04/2013 08:14 AM, Ferrous Cranus wrote:
> Instead of writing the above html data inside my html template how
> would i write it with a for that then will be substituted by the
> python script?

What templating system are you using?  Django's?

> can you please write an example for me that user "files.html" and
> gets populates by "files.py" ?

If you're using a CGI script, just use a normal python for loop and
print out the stuff you want using this kind of notation:

for x in xrange(4):
    print "<tr><td>{0}</td></tr>".format(x)


Another alternative is to make your own templating system.  Have it load
and parse the html file (maybe using one of the xml or html parsers),
and substitude some sort of field marker for data.  But that is
re-inventing the wheel.

http://wiki.python.org/moin/Templating

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Embedding a for inside an html template for substitution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-03-04 07:14 -0800
  Re: Embedding a for inside an html template for substitution Michael Torrie <torriem@gmail.com> - 2013-03-04 08:59 -0700
    Re: Embedding a for inside an html template for substitution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-03-04 09:22 -0800
      Re: Embedding a for inside an html template for substitution Michael Torrie <torriem@gmail.com> - 2013-03-04 20:56 -0700
      Re: Embedding a for inside an html template for substitution Roland Koebler <r.koebler@yahoo.de> - 2013-03-05 18:16 +0100
    Re: Embedding a for inside an html template for substitution Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-03-04 09:22 -0800
  Re: Embedding a for inside an html template for substitution nagia.retsina@gmail.com - 2013-03-04 23:46 -0800

csiph-web