Size: 289
Comment:
|
← Revision 11 as of 2021-06-18 14:38:35 ⇥
Size: 1977
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
## page was renamed from virtualenv | |
Line 6: | Line 7: |
* cd /tmp | |
Line 7: | Line 9: |
* tar xvfz virtualenv-X.X.tar.gz * cd virtualenv-X.X |
* tar xvfz virtualenv-1.10.1.tar.gz * cd virtualenv-1.10.1 |
Line 10: | Line 12: |
== Setup virtualenv with python3 in Debian == {{{#!highlight bash cd ~/tmp mkdir projectx cd projectx sudo apt install python3-venv python3 -m venv virtenv . virtenv/bin/activate pip install cherrypy routes jinja2 find . nano jinja2test.py mkdir templates nano templates/test.html python3 jinja2test.py }}} === jinja2test.py === {{{#!highlight python import sys sys.stdout = sys.stderr import cherrypy from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('/home/vitor/tmp/projectx/templates')) cherrypy.config.update({'environment': 'embedded'}) class Jinja2Test(object): @cherrypy.expose def index(self): return "Hello World Jinja2Test!!!!" @cherrypy.expose def add(self,param1,param2): return str( int(param1)+int(param2) ) @cherrypy.expose def testpage(self): t = env.get_template('test.html') navItems=[] for i in range(1,10): navItems.append( {'href':'hrefx','caption':'cap %d'%(i) } ) return t.render( titlex="Titleeeee" , navigation=navItems ) jjtest = Jinja2Test() cherrypy.server.socket_host = '0.0.0.0' cherrypy.quickstart(jjtest) }}} === templates/test.html === {{{#!highlight xml <html> <head></head> <body> <ul id="navigation"> {% if navigation|count > 0 %} {% for item in navigation %} <li> <a href="{{item.href}}">{{item.caption}}</a> </li> {% endfor %} {% endif %} </ul> <h1>My webpage {{titlex}} </h1> </body> </html> }}} |
virtualenv
virtualenv is a tool to create isolated Python environments.
Install from source
- su
- cd /tmp
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.10.1.tar.gz
- tar xvfz virtualenv-1.10.1.tar.gz
- cd virtualenv-1.10.1
- python setup.py install
Setup virtualenv with python3 in Debian
jinja2test.py
1 import sys
2 sys.stdout = sys.stderr
3 import cherrypy
4
5 from jinja2 import Environment, FileSystemLoader
6 env = Environment(loader=FileSystemLoader('/home/vitor/tmp/projectx/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 cherrypy.server.socket_host = '0.0.0.0'
27 cherrypy.quickstart(jjtest)