PHP + TinyButStrong Python replacement

P

pistacchio

hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:

<div align="center" class="title-page"> [var.x] </div>

and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:

<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>

in the previous code it cycles throu all the values of the array blk1.

it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.

now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.

1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings etc)
3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
4. object oriented programming is not required (better: i prefer
plain old procedural programming).

any help? thanks in advance
 
M

Mike Driscoll

hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:

<div align="center" class="title-page"> [var.x] </div>

and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:

<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>

in the previous code it cycles throu all the values of the array blk1.

it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.

now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.

    1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
    2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings etc)
    3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
    4. object oriented programming is not required (better: i prefer
plain old procedural programming).

any help? thanks in advance

Did you look at TurboGears or Django? TG uses Kid in the 1.x series
and Genshi in 2.x (I think) for templating purposes. There's also
Cheetah, one of the more powerful Python templating engines out there.

http://genshi.edgewall.org/
http://www.kid-templating.org/
http://www.cheetahtemplate.org/
http://turbogears.org/

Maybe those links will get you going.

Mike
 
P

pistacchio

Mike Driscoll ha scritto:
hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:

<div align="center" class="title-page"> [var.x] </div>

and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:

<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>

in the previous code it cycles throu all the values of the array blk1.

it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.

now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.

1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings etc)
3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
4. object oriented programming is not required (better: i prefer
plain old procedural programming).

any help? thanks in advance

hi, thanks for replaying
Did you look at TurboGears or Django? TG uses Kid in the 1.x series
and Genshi in 2.x (I think) for templating purposes. There's also
Cheetah, one of the more powerful Python templating engines out there.

django is exacly the kind of giant i'm trying to avoid

the first lines of the tutorial read:
"First, make sure you have CherryPy 3.0.x installed"
Now, cherrypy is something that is not properly "include a file and get
going!"

kid seems to have a non-linear approach, but i may give it a try

cheetah was something that i already considered using. have i to
"install" it or can i just import it?

same problem as with django!
 
D

Diez B. Roggisch

pistacchio said:
Mike Driscoll ha scritto:
hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:

<div align="center" class="title-page"> [var.x] </div>

and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:

<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>

in the previous code it cycles throu all the values of the array blk1.

it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.

now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.

1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings
etc)
3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
4. object oriented programming is not required (better: i prefer
plain old procedural programming).

any help? thanks in advance

hi, thanks for replaying
Did you look at TurboGears or Django? TG uses Kid in the 1.x series
and Genshi in 2.x (I think) for templating purposes. There's also
Cheetah, one of the more powerful Python templating engines out there.

django is exacly the kind of giant i'm trying to avoid

the first lines of the tutorial read:
"First, make sure you have CherryPy 3.0.x installed"
Now, cherrypy is something that is not properly "include a file and get
going!"

kid seems to have a non-linear approach, but i may give it a try

cheetah was something that i already considered using. have i to
"install" it or can i just import it?

You will need to install any of these. It is part of how python is designed.
Extendability comes with a price-tag.

I don't know for sure, but I guess the cherrypy-requirement of genshi is
more for the tutorial, not for the templating itself.

Diez
 
P

pistacchio

Diez B. Roggisch ha scritto:
pistacchio said:
Mike Driscoll ha scritto:
hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:

<div align="center" class="title-page"> [var.x] </div>

and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:

<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>

in the previous code it cycles throu all the values of the array blk1.

it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.

now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.

1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings
etc)
3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
4. object oriented programming is not required (better: i prefer
plain old procedural programming).

any help? thanks in advance
hi, thanks for replaying
Did you look at TurboGears or Django? TG uses Kid in the 1.x series
and Genshi in 2.x (I think) for templating purposes. There's also
Cheetah, one of the more powerful Python templating engines out there.
django is exacly the kind of giant i'm trying to avoid
the first lines of the tutorial read:
"First, make sure you have CherryPy 3.0.x installed"
Now, cherrypy is something that is not properly "include a file and get
going!"
kid seems to have a non-linear approach, but i may give it a try
cheetah was something that i already considered using. have i to
"install" it or can i just import it?

You will need to install any of these. It is part of how python is designed.
Extendability comes with a price-tag.

well, the problema is exacly that i'm looking for a python module, not
for a python library.
most of the tasks i need are just:
1. on the shoulders of the existing standard cgi modules, automate an
render easier the handling of things such as sessions and requests
2. on the shoulders of the existing standard regex module, have a simple
but complete templating engine and html-related encoder
 
G

George Sakkis

Diez B. Roggisch ha scritto:


pistacchio wrote:
Mike Driscoll ha scritto:
hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:
<div align="center" class="title-page"> [var.x] </div>
and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:
<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>
in the previous code it cycles throu all the values of the array blk1..
it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.
now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.
    1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
    2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings
etc)
    3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
    4. object oriented programming is not required (better: i prefer
plain old procedural programming).
any help? thanks in advance
hi, thanks for replaying
Did you look at TurboGears or Django? TG uses Kid in the 1.x series
and Genshi in 2.x (I think) for templating purposes. There's also
Cheetah, one of the more powerful Python templating engines out there.
django is exacly the kind of giant i'm trying to avoid
http://genshi.edgewall.org/
the first lines of the tutorial read:
"First, make sure you have CherryPy 3.0.x installed"
Now, cherrypy is something that is not properly "include a file and get
going!"
http://www.kid-templating.org/
kid seems to have a non-linear approach, but i may give it a try
http://www.cheetahtemplate.org/
cheetah was something that i already considered using. have i to
"install" it or can i just import it?
You will need to install any of these. It is part of how python is designed.
Extendability comes with a price-tag.

well, the problema is exacly that i'm looking for a python module, not
for a python library.

What does it matter if it's a single file or a dozen under a package ?
"Installation" for pure Python packages can be as simple as copying
the package under any directory in your PYTHONPATH.

Check out Mako (http://www.makotemplates.org/), it's pretty powerful
and fast.

George
 
P

pistacchio

George Sakkis ha scritto:
Diez B. Roggisch ha scritto:


pistacchio wrote:
Mike Driscoll ha scritto:
hi! i'm a php user and a python programmer. i'd love to use python for
my server side needs but i can't seem to find what i'm looking for. for
most of my php work i use mysql and tinyButStrong
(http://www.tinybutstrong.com) which is a very lightweight template
engine that offers powerful functionalities. you insert TBS tags in web
pages like:
<div align="center" class="title-page"> [var.x] </div>
and it replaces [var.x] with the value of global variable x. it also
makes blocks (and nested blocks) easy to implement:
<p class="text-example2"> [blk1;block=begin] [blk1.val]<br>
[blk1;block=end] </p>
in the previous code it cycles throu all the values of the array blk1.
it does many more things, like htlm escaping, url and js encoding etc,
conditional displaying etc, but it is not more confusing that inserting
pieces of code into the HTML (aka: littering the code and kissing
goodbye to the code/presentation separation). it comes in the form of a
single file with a single class that you can easily include in the code
and go.
now, i've searched the net and it seems full of python-based frameworks
for doing server side scripting and templating, but none that suits my
needs.
1. i like writing code and i like control. i mean, open up the
simplest text editor and write in it. i don't want something that is
command-line driven or that writes code for me like ">>>
makePagesFromThisDatabase()".
2. i want something very lightweight. i don't want dozen of options,
pre-made blogging parts ecc. i just need a good non invasive template
engine and the basic functions for server side scripting, like session
managing, request parsing, functions to manipulate html code (encodings
etc)
3. i don't want to beg my hosting provider to install the libraries.
a simple include file should do the work.
4. object oriented programming is not required (better: i prefer
plain old procedural programming).
any help? thanks in advance
hi, thanks for replaying
Did you look at TurboGears or Django? TG uses Kid in the 1.x series
and Genshi in 2.x (I think) for templating purposes. There's also
Cheetah, one of the more powerful Python templating engines out there.
django is exacly the kind of giant i'm trying to avoid
http://genshi.edgewall.org/
the first lines of the tutorial read:
"First, make sure you have CherryPy 3.0.x installed"
Now, cherrypy is something that is not properly "include a file and get
going!"
http://www.kid-templating.org/
kid seems to have a non-linear approach, but i may give it a try
http://www.cheetahtemplate.org/
cheetah was something that i already considered using. have i to
"install" it or can i just import it?
You will need to install any of these. It is part of how python is designed.
Extendability comes with a price-tag.
well, the problema is exacly that i'm looking for a python module, not
for a python library.

What does it matter if it's a single file or a dozen under a package ?
"Installation" for pure Python packages can be as simple as copying
the package under any directory in your PYTHONPATH.

well, it doesn't matter if it's a single file or a package, but it
_does_ matter if you have to put them under the path where python is
installed because, in a typical shared web hosting environment (such the
one that i use) you don't have access to system directories.
Check out Mako (http://www.makotemplates.org/), it's pretty powerful
and fast.

woudl you suggest mako over cheetah?
 
P

python

Pistacchio,

Templite
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496702

A light-weight (~40 lines), fully functional, general purpose templating
engine, allowing you to embed python code directly into your text. This
engine is suitable for any templating (not only HTML/XML), and is
minimal (40 lines of code!) and fast (all preprocessing is done in
"compile time")

Quote: "Very nice. That's just the right amount of markup for embedding
Python into html documents."

Malcolm
 
T

Terry Reedy

| well, it doesn't matter if it's a single file or a package, but it
| _does_ matter if you have to put them under the path where python is
| installed because, in a typical shared web hosting environment (such the
| one that i use) you don't have access to system directories.

When you do an import, the *first* place the interpreter looks is the
*current* directory, which usually is the directory containing the main
file. That is because the first entry in sys.path is ''. So put
'template.py' in the same directory as my_web_code.py. If necessary, one
can add an entry to the beginning of sys.path.

No need to touch the site-packages directory. The only reason to put
something there is to make modules available to any code in any directory
without putting a copy in each directory containing python files.

tjr
 
B

bruno.desthuilliers

George Sakkis ha scritto: (snip)

well, it doesn't matter if it's a single file or a package, but it
_does_ matter if you have to put them under the path where python is
installed because, in a typical shared web hosting environment (such the
one that i use) you don't have access to system directories.

You *never* have to install anything in the default path - install
your python libs wherever you want, and just make sure this wherever
is in your python path (usually via the PYTHONPATH environment
variable).
woudl you suggest mako over cheetah?

As far as I'm concerned, I would. Now if you're looking for a
somewhat barebone MVC framework, you may want to have a look at
web.py.
 
P

pistacchio

(e-mail address removed) ha scritto:
You *never* have to install anything in the default path - install
your python libs wherever you want, and just make sure this wherever
is in your python path (usually via the PYTHONPATH environment
variable).

again, in a shared environment, you don't have access to environment
variables. all you can do is copy files in your own little directory,
and that's it. this directory is never something like /share/python, but
something like /home/averagejoe. and /home/averagejoe is not usually in
the PYTHONPATH
As far as I'm concerned, I would. Now if you're looking for a
somewhat barebone MVC framework, you may want to have a look at
web.py.

i've tried mako. sees to work fine for me, both for its potential and
for its "installation" method. in fact i just copied it under my own
directory

/home/averagejoe
test.py
/mako
mako stuff

and the following testcase worked well:

from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()

can i do the same with web.py? mind that i work under an apache
environment (mod_python).

now, back to mako. can you provide an example of blocks and nested
blocks in mako? the documentation doesn't seem to be too clear in this
reguard.

for example, if i want to show a table with a list of restaurants
(gathered from a db query), i can construct a template like this:

<table>
% for rest in restaurants:
<tr>${rest}<tr>
% endfor
</table>

but what if if each restaurant has a list of dishes (pasta, pizza, meat,
pie) and some (or each) dish has the ingrediets? is it just like
embedding pure python into the template ( like $(rest['dish']) and
$rest['dish']['ingredient']) )?

thanks for you interest
 
B

Bruno Desthuilliers

pistacchio a écrit :
(e-mail address removed) ha scritto:

again, in a shared environment, you don't have access to environment
variables.

Depends on the "shared environment". But even if you can't set
PYTHONPATH, you can always import sys and append (or prepend) to
sys.path before doing any other import.
> all you can do is copy files in your own little directory,
and that's it. this directory is never something like /share/python, but
something like /home/averagejoe. and /home/averagejoe is not usually in
the PYTHONPATH


i've tried mako. sees to work fine for me, both for its potential and
for its "installation" method. in fact i just copied it under my own
directory

/home/averagejoe
test.py
/mako
mako stuff

and the following testcase worked well:

from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()

can i do the same with web.py?

Can't tell, never used it. But how to deploy it is very certainly
documented on the project's page.
mind that i work under an apache
environment (mod_python).

mod_python ? Fine. And, if I may ask, did you actually took time to read
the FineManual(tm) ?-)

http://www.modpython.org/live/mod_python-3.3.1/doc-html/dir-other-pp.html

now, back to mako. can you provide an example of blocks and nested
blocks in mako? the documentation doesn't seem to be too clear in this
reguard.

for example, if i want to show a table with a list of restaurants
(gathered from a db query), i can construct a template like this:

<table>
% for rest in restaurants:
<tr>${rest}<tr>
% endfor
</table>

but what if if each restaurant has a list of dishes (pasta, pizza, meat,
pie)

Depends... What kind of object is 'rest' ? How is this list named ?
and some (or each) dish has the ingrediets?

Same question.
is it just like
embedding pure python into the template ( like $(rest['dish']) and
$rest['dish']['ingredient']) )?

What goes inside ${} are ordinary Python expressions, yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top