how to creating html files with python

K

krishnakant Mane

hello,
I have one strange requirement,
I need to create html files through python and add some data from the database.
it is a GUI based application developed in WX python.
and the reports need to come out in html for some strange reason which
is off topic to discuss here.
but the point is that how do I do it?
should I create a normal file object and write the html with the data
into it or are there some modules to do it?
regards,
Krishnakant.
 
D

Diez B. Roggisch

krishnakant said:
hello,
I have one strange requirement,
I need to create html files through python and add some data from the database.
it is a GUI based application developed in WX python.
and the reports need to come out in html for some strange reason which
is off topic to discuss here.
but the point is that how do I do it?
should I create a normal file object and write the html with the data

Essentially, yes.
into it or are there some modules to do it?


There are a bazillion templating systems out there. Beginning with
python's own string interpolation, to

KID, genshi, Mako, tenjin, cheeta, ... <continue>

Search this NG for python templating engines, and you'd be overwhelmed
by the answers.

Happy chosing your evil,

Diez
 
G

George Sakkis

I have one strange requirement,
I need to create html files through python and add some data from the database.

The only strange thing here is that you think this is a strange
requirement :) This is quite typical, and practically required for web
development. As Diez pointed out, your main problem will be which of
the dozen or so template packages to pick. Depending on your criteria
(expressive power, syntax close to python, performance, stability
etc.) you may narrow it down to a handful.

George
 
B

BartlebyScrivener

The only strange thing here is that you think this is a strange
requirement :) This is quite typical, and practically required for web
development.

I was wondering about this myself the other day. Suppose you wanted to
get by on the cheap without setting up a whole new Joomla or WordPress
installation for another smallish blog or website where you are the
only poster, and all you need is simple CMS.

How hard would it be to create, say, a calendar of events, or news
postings using MySQL and Python and HTML. Create the page on your
local machine using Python templating, and then just post the HTML
code daily?

I'm a rank amateur, but was wondering if this is silly and making
work, or if one of those templating systems you all are mentioning
would work for simple CMS and calendaring?

Thanks,

rd
 
K

krishnakant Mane

hi George,

database.

The only strange thing here is that you think this is a strange
requirement :) This is quite typical, and practically required for web
development. As Diez pointed out, your main problem will be which of
the dozen or so template packages to pick. Depending on your criteria
I am finding it difficult to choose.
my only requirement is to create an htmo file with normal html taggs
but the values come from a database connection.
so I want to get rid of doing the entire concatination right from
start till end. I don't mind opening a file and doing file.write()
but it will be nice of some module to help me get the data
concatinated with taggs and rather even better if I can do complex
things like creating an html table whos rows contain data coming from
a result set.
here I would like to have the tagging more like functions, some thing
like report.bold("this must be bold ") and this function to return a
line with the bolded html which looks in the file as <b> this must be
bold </b>
so instead of I doing the concatination myself, python makes it easy.
and I will have lot of complex tables etc to do like this.
so please help me choose one.
regards,
Krishnakant.
 
P

paul

krishnakant Mane schrieb:
[snip]
so instead of I doing the concatination myself, python makes it easy.
and I will have lot of complex tables etc to do like this.
so please help me choose one.
Did you actually looked for a template language as suggested here?
Now to make your life easier: If you like XML, use genshi. If you plan
to generate something else than HTML, use cheetah. Use google or
whatever search engine you prefer to find those packages.

cheers
Paul
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top