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


Groups > comp.lang.python > #42859 > unrolled thread

can anyone help me in developing a simple webpage in jinja2

Started bySatabdi Mukherjee <satamukh@gmail.com>
First post2013-04-05 15:41 -0700
Last post2013-04-07 19:29 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  can anyone help me in developing a simple webpage in jinja2 Satabdi Mukherjee <satamukh@gmail.com> - 2013-04-05 15:41 -0700
    Re: can anyone help me in developing a simple webpage in jinja2 Jan Riechers <janpeterr@freenet.de> - 2013-04-06 10:15 +0300
    Re: can anyone help me in developing a simple webpage in jinja2 Chris Angelico <rosuav@gmail.com> - 2013-04-06 19:00 +1100
    Re: can anyone help me in developing a simple webpage in jinja2 Cousin Stanley <cousinstanley@gmail.com> - 2013-04-07 19:29 +0000

#42859 — can anyone help me in developing a simple webpage in jinja2

FromSatabdi Mukherjee <satamukh@gmail.com>
Date2013-04-05 15:41 -0700
Subjectcan anyone help me in developing a simple webpage in jinja2
Message-ID<e8c498f4-348c-415f-927c-f871551d9a82@googlegroups.com>
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 
i am trying in this way but showing invalid syntax error

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>My Webpage</title>
</head>
<body>
    <ul id="navigation">
    {% for item in navigation %}
        <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
    {% endfor %}
    </ul>

    <h1>My Webpage</h1>
    {{ a_variable }}
</body>
</html>

[toc] | [next] | [standalone]


#42901

FromJan Riechers <janpeterr@freenet.de>
Date2013-04-06 10:15 +0300
Message-ID<mailman.194.1365232819.3114.python-list@python.org>
In reply to#42859
On 06.04.2013 01:41, 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
> i am trying in this way but showing invalid syntax error
>
[...]
>      <ul id="navigation">
>      {% for item in navigation %}
>          <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
>      {% endfor %}
>      </ul>
>
>      <h1>My Webpage</h1>
>      {{ a_variable }}
[...]
>

Hello,

the jinja2 syntax is correct that way, see also this for reference for 
variable naming:
http://jinja.pocoo.org/docs/templates/index.html#variables

The invalid syntax is raised when? Can you post the error a bit more 
detailed, this will help giving you any advice.

If you know the code part raising the error and you post it, this will 
also help.

Jan

[toc] | [prev] | [next] | [standalone]


#42902

FromChris Angelico <rosuav@gmail.com>
Date2013-04-06 19:00 +1100
Message-ID<mailman.195.1365235253.3114.python-list@python.org>
In reply to#42859
On Sat, Apr 6, 2013 at 6:15 PM, Jan Riechers <janpeterr@freenet.de> wrote:
> The invalid syntax is raised when? Can you post the error a bit more
> detailed, this will help giving you any advice.
>
> If you know the code part raising the error and you post it, this will also
> help.

Agreed. But my guess would be the lack of colon on the for loop...
which would be highlighted by the error thrown.

ChrisA

[toc] | [prev] | [next] | [standalone]


#43015

FromCousin Stanley <cousinstanley@gmail.com>
Date2013-04-07 19:29 +0000
Message-ID<kjshej$kg8$1@dont-email.me>
In reply to#42859
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web