Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > can anyone help me in developing a simple webpage in jinja2

Reply
Thread Tools

can anyone help me in developing a simple webpage in jinja2

 
 
Satabdi Mukherjee
Guest
Posts: n/a
 
      04-05-2013
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>
 
Reply With Quote
 
 
 
 
Jan Riechers
Guest
Posts: n/a
 
      04-06-2013
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/template...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
 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      04-06-2013
On Sat, Apr 6, 2013 at 6:15 PM, Jan Riechers <(E-Mail Removed)> 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
 
Reply With Quote
 
Cousin Stanley
Guest
Posts: n/a
 
      04-07-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jinja2 installation help Robert Iulian Python 6 02-09-2013 01:15 PM
Jinja2 + jQuery tabs widget JoeM Python 2 03-14-2012 02:50 PM
cause webpage one to reload when webpage two is closed. Paul ASP .Net 14 06-19-2008 03:02 PM
check if a webpage is forwarding to a other webpage martijn@gamecreators.nl Python 1 09-06-2005 02:27 PM
Email contents of webpage or Form on webpage w/o using Server scripting sifar Javascript 5 08-24-2005 05:47 PM



Advertisments