>
## page was renamed from virtualenv
= virtualenv =
virtualenv is a tool to create isolated Python environments.
== Install from source ==
{{{#!highlight sh
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 ==
{{{#!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
{% if navigation|count > 0 %}
{% for item in navigation %}
-
{{item.caption}}
{% endfor %}
{% endif %}
My webpage {{titlex}}
}}}