can anyone help me in developing a simple webpage in jinja2
Cousin Stanley
cousinstanley at gmail.com
Sun Apr 7 15:29:24 EDT 2013
Satabdi Mukherjee wrote:
> i am a rookie in python and i am trying
> to develop a simple webpage using jinja2.
>
> can anyone please help me how to do that
You might try using your jinja template
with named tuples ....
# -------------------------------------------
from jinja2 import Template
from collections import namedtuple as NT
nt = NT( 'Navigation' , 'href caption' )
n1 = nt( 'http://python.org' , 'python' )
n2 = nt( 'http://cython.org' , 'cython' )
n3 = nt( 'http://jython.org' , 'jython' )
n4 = nt( 'http://pypy.org/' , 'pypy' )
nav = ( n1 , n2 , n3 , n4 )
tmpl = Template( '''\
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<ul id="navigation">
{% for url , caption in navigation %}
<li><a href="{{ url }}">{{ caption }}</a></li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
</body>
</html>
''' )
print tmpl.render(
variable = 'Navigation' , navigation = nav )
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list