Making a pass form cgi => webpy framework

Νίκος nikos at superhost.gr
Mon Jun 24 03:32:51 EDT 2013


Στις 24/6/2013 7:37 πμ, ο/η Michael Torrie έγραψε:
>> Why use mako's approach which requires 2 files(an html template and the
>> actual python script rendering the data) when i can have simple print
>> statements inside 1 files(my files.py script) ?
>> After all its only one html table i wish to display.
> Sooner or later your needs grow to the point where your single python
> CGI file is mixing so much html and python code that it becomes unwieldy.

Yes Michale indeed, my pelatologio.py is filled with print html statemnt 
and actual python code. it lloks like this:

	#print all client profiles
	print('''
	<body background="/data/images/bluetiles.jpg">
	<center><h3><font color=yellow size=5>~ Πελατολόγιο ~<br>
	<font color=white size=5>
	Πελάτες:   <font color=red>    %s   </font>
	Επισκευές: <font color=silver> %s   </font>
	Χρήματα:   <font color=violet> %s € </font><br><br>
	<table border=5 cellpadding=5 bgcolor=black>
	<th><font color=lime size=5> Πελάτης </th><th><font color=orange 
size=5> Τηλέφωνο </th>
	<th><font color=tomato size=5> Επισκευές </th><th><font color=cyan 
size=5> Σύνολο </th>
	''' % (clients, hits, money) )

	for row in data:
		(name, phone, hits, money) = row
		
		print('''	
		<tr>
			<td><center><a 
href="http://superhost.gr/cgi-bin/pelatologio.py/?log=%s"> <font 
color=lime size=4> %s </a></td>
			<td><center><font color=orange size=4> %s </td>
			<td><center><font color=tomato size=4> %s </td>
			<td><center><font color=cyan   size=4> %s </td>
		</tr>
		''' % (name, name, phone, hits, money) )
===========================================

Apart form the fact that i will need to separate the design form the 
code, if i didn't is there an easiest way to  print tables and forms by 
using python's html generation functions and not plain print statements 
that will make the code more clear?


And also in my pelatologio.py and other script i use if statements to 
check if user submitted data or not so to print them on screen and then 
exit, like modularization.

foe example:

if( log ):
	name = log
	print this and this

if( seek ):
	other statements
	print this and this

How will i be able to do this if i use an html template
every time an if() runs all the html will run and not a part of it.

Thanks.




-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list