473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP + TinyButStrong Python replacement

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=begi n] [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 ">>>
makePagesFromTh isDatabase()".
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
Jun 27 '08
12 1409
br************* ****@gmail.com ha scritto:
On 7 mai, 16:17, pistacchio <pistacc...@gma il.comwrote:
>George Sakkis ha scritto:
(snip)
>>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.

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
>>Check out Mako (http://www.makotemplates.org/), it's pretty powerful
and fast.
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.
i've tried mako. sees to work fine for me, both for its potential and
for its "installati on" 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.rend er()

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}<t r>
% 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
Jun 27 '08 #11
-On [20080507 15:06], Mike Driscoll (ky******@gmail .com) wrote:
>http://genshi.edgewall.org/
http://www.kid-templating.org/
http://www.cheetahtemplate.org/
http://turbogears.org/
Add the following to that list:

http://jinja.pocoo.org/
http://www.makotemplates.org/

I think Jinja and Mako are currently two of the fastest around.

--
Jeroen Ruigrok van der Werven <asmodai(-at-)in-nomine.org/ asmodai
イェルーン ラウフãƒ*ッ ク ヴァン デル ウェルヴェ ン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
If Winter comes, can Spring be far behind..?
Jun 27 '08 #12
pistacchio a écrit :
br************* ****@gmail.com ha scritto:
>On 7 mai, 16:17, pistacchio <pistacc...@gma il.comwrote:
>>George Sakkis ha scritto:
(snip)
>>>What does it matter if it's a single file or a dozen under a package ?
"Installatio n" 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.

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.
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
>>>Check out Mako (http://www.makotemplates.org/), it's pretty powerful
and fast.
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.

i've tried mako. sees to work fine for me, both for its potential and
for its "installati on" 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.rend er()

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_py...-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}<t r>
% 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.

Jun 27 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
2859
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville Vainio http://www.students.tut.fi/~vainio24
14
2858
by: David MacQuigg | last post by:
I am starting a new thread so we can avoid some of the non-productive argument following my earlier post "What is good about Prothon". At Mr. Hahn's request, I will avoid using the name "Prothon" in the subject of any post to this newsgroup. Please ignore the old thread. I've also updated my webpage http://ece.arizona.edu/~edatools/Python Anyone with some good ideas for "Python 3" is welcome to contribute. I hope GvR won't sue me for...
5
2904
by: Vamsee Krishna Gomatam | last post by:
Hello, I'm having some problems understanding Regexps in Python. I want to replace "<google>PHRASE</google>" with "<a href=http://www.google.com/search?q=PHRASE>PHRASE</a>" in a block of text. How can I achieve this in Python? Sorry for the naive question but the documentation is really bad :-( Regards, GVK
3
9741
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject) method/function, I need the second argument 'replacement' to be another regular expression ( not a string) . So when I find a 'certain kind of string' in
17
8095
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
40
2851
by: walterbyrd | last post by:
I mean other than sysadmins, programmers, and web-site developers? I have heard of some DBAs who use a lot of python. I suppose some scientists. I think python is used in bioinformatics. I think some math and physics people use python. I suppose some people use python to learn "programming" in general. Python would do well as a teaching language.
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.