Size: 2432
Comment:
|
Size: 2906
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
<<TableOfContents(2)>> ## page was renamed from Jinja2 |
|
Line 3: | Line 5: |
* https://palletsprojects.com/p/jinja/ * https://jinja.palletsprojects.com/en/2.10.x/ |
|
Line 5: | Line 9: |
* wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz * cp Jinja2-2.7.1.tar.gz /tmp * tar xvzf Jinja2-2.7.1.tar.gz * cd Jinja2-2.7.1 * python setup.py build * python setup.py install |
{{{#!highlight sh wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.1.tar.gz cp Jinja2-2.7.1.tar.gz /tmp tar xvzf Jinja2-2.7.1.tar.gz cd Jinja2-2.7.1 python setup.py build python setup.py install }}} |
Line 13: | Line 19: |
{{{ | {{{#!highlight python |
Line 25: | Line 31: |
Check [[Python/CherryPy]] {{{#!highlight sh |
|
Line 28: | Line 35: |
}}} | |
Line 29: | Line 37: |
File /var/www/htdocs/jinja2test/jinja2test.wsgi | File '''/var/www/htdocs/jinja2test/jinja2test.wsgi''' |
Line 48: | Line 56: |
def template(self): | def testpage(self): |
Line 52: | Line 60: |
navItems.append( {'href':'aaa','caption':'cap %d'%(i) } ) return t.render( variable="ASDDDD" , navigation=navItems ) |
navItems.append( {'href':'hrefx','caption':'cap %d'%(i) } ) return t.render( titlex="Titleeeee" , navigation=navItems ) |
Line 59: | Line 67: |
File /var/www/htdocs/jinja2test/templates/test.html | File '''/var/www/htdocs/jinja2test/templates/test.html''' |
Line 65: | Line 73: |
{% if navigation|count > 0 %} | |
Line 70: | Line 79: |
{% endif %} | |
Line 71: | Line 81: |
<h1>My webpage {{variable}} </h1> </body> |
<h1>My webpage {{titlex}} </h1> </body> |
Line 76: | Line 86: |
Add virtual host in /etc/httpd/vhosts.conf | Add virtual host in '''/etc/httpd/vhosts.conf''' |
Line 88: | Line 98: |
Add host to /etc/hosts | Add host to '''/etc/hosts''' |
Line 92: | Line 102: |
Restart apache * /etc/rc.d/rc.httpd restart Open URLs: * http://localhostjinja2test/ * http://localhostjinja2test/add/3/4 * http://localhostjinja2test/testpage |
Jinja2
Jinja2 is a modern and designer friendly templating language for Python, modelled after Django’s templates.
Slackware 14 installation
Check installation
Jinja2 test
Check Python/CherryPy
File /var/www/htdocs/jinja2test/jinja2test.wsgi
1 import sys
2 sys.stdout = sys.stderr
3 import cherrypy
4
5 from jinja2 import Environment, FileSystemLoader
6 env = Environment(loader=FileSystemLoader('/var/www/htdocs/jinja2test/templates'))
7
8 cherrypy.config.update({'environment': 'embedded'})
9
10 class Jinja2Test(object):
11 @cherrypy.expose
12 def index(self):
13 return "Hello World Jinja2Test!!!!"
14 @cherrypy.expose
15 def add(self,param1,param2):
16 return str( int(param1)+int(param2) )
17 @cherrypy.expose
18 def testpage(self):
19 t = env.get_template('test.html')
20 navItems=[]
21 for i in range(1,10):
22 navItems.append( {'href':'hrefx','caption':'cap %d'%(i) } )
23 return t.render( titlex="Titleeeee" , navigation=navItems )
24
25 jjtest = Jinja2Test()
26 application = cherrypy.Application(jjtest, script_name=None, config=None)
File /var/www/htdocs/jinja2test/templates/test.html
Add virtual host in /etc/httpd/vhosts.conf
<VirtualHost *:80> ServerName localhostjinja2test DocumentRoot "/var/www/htdocs/jinja2test" WSGIScriptAlias / /var/www/htdocs/jinja2test/jinja2test.wsgi <Directory "/var/www/htdocs/jinja2test"> Require local </Directory> </VirtualHost>
Add host to /etc/hosts
127.0.0.1 localhostjinja2test
Restart apache
- /etc/rc.d/rc.httpd restart
Open URLs: