Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48979 > unrolled thread

Making a pass form cgi => webpy framework

Started byΝίκος <nikos@superhost.gr>
First post2013-06-23 16:01 +0300
Last post2013-06-28 07:28 -0700
Articles 19 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-23 16:01 +0300
    Re: Making a pass form cgi => webpy framework rurpy@yahoo.com - 2013-06-23 07:57 -0700
      Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-23 18:15 +0300
        Re: Making a pass form cgi => webpy framework rurpy@yahoo.com - 2013-06-23 15:29 -0700
          Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-24 04:44 +0300
            Re: Making a pass form cgi => webpy framework Michael Torrie <torriem@gmail.com> - 2013-06-23 22:37 -0600
              Re: Making a pass form cgi => webpy framework rusi <rustompmody@gmail.com> - 2013-06-23 21:49 -0700
              Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-24 10:32 +0300
                Re: Making a pass form cgi => webpy framework rusi <rustompmody@gmail.com> - 2013-06-24 08:51 -0700
            Re: Making a pass form cgi => webpy framework rurpy@yahoo.com - 2013-06-25 11:00 -0700
              Re: Making a pass form cgi => webpy framework Joel Goldstick <joel.goldstick@gmail.com> - 2013-06-25 14:53 -0400
                Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-26 08:31 +0300
              Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-27 16:32 +0300
                Re: Making a pass form cgi => webpy framework Cameron Simpson <cs@zip.com.au> - 2013-06-28 09:08 +1000
                  Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-28 06:38 +0300
                    Re: Making a pass form cgi => webpy framework Robert Kern <robert.kern@gmail.com> - 2013-06-28 10:35 +0100
                      Re: Making a pass form cgi => webpy framework Νίκος <nikos@superhost.gr> - 2013-06-28 13:15 +0300
                        Re: Making a pass form cgi => webpy framework Robert Kern <robert.kern@gmail.com> - 2013-06-28 11:30 +0100
                        Re: Making a pass form cgi => webpy framework rusi <rustompmody@gmail.com> - 2013-06-28 07:28 -0700

#48979 — Making a pass form cgi => webpy framework

FromΝίκος <nikos@superhost.gr>
Date2013-06-23 16:01 +0300
SubjectMaking a pass form cgi => webpy framework
Message-ID<kq6rip$51m$1@news.grnet.gr>
Hello, as you all know i'am using cgi method for my web script.

I have been told that webpy is the way to go sor script simple enough as 
mines.

Can you please show me the simplest example you can think of utilizing a 
templates (index.html) and a python script (metrites.py) ?

I want to see if it is easy to ditch cgi and pass to the world of web 
frameworks.

thank you.
-- 
What is now proved was at first only imagined!

[toc] | [next] | [standalone]


#48983

Fromrurpy@yahoo.com
Date2013-06-23 07:57 -0700
Message-ID<2978d13b-ca0d-4f3b-bd62-a2fcf346c46a@googlegroups.com>
In reply to#48979
On 06/23/2013 07:01 AM, Νίκος wrote:> Hello, as you all know i'am using cgi method for my web script.
> 
> I have been told that webpy is the way to go sor script simple enough as 
> mines.
> 
> Can you please show me the simplest example you can think of utilizing a 
> templates (index.html) and a python script (metrites.py) ?
> 
> I want to see if it is easy to ditch cgi and pass to the world of web 
> frameworks.

I don't know anything about webpy so I can help with that.

But I did want to say that you can use templates without
using a web framework like webpy.  They are very useful 
even with cgi code and can simplify the cgi code a lot.

For my web server stuff (relatively small sites with low 
traffic) cgi is fine (simple, easy to debug, lots of online
documentation and help) so I don't buy the "cgi is dead"
comments seen frequently here.

[toc] | [prev] | [next] | [standalone]


#48984

FromΝίκος <nikos@superhost.gr>
Date2013-06-23 18:15 +0300
Message-ID<kq73fg$51m$2@news.grnet.gr>
In reply to#48983
Στις 23/6/2013 5:57 μμ, ο/η rurpy@yahoo.com έγραψε:
> On 06/23/2013 07:01 AM, Νίκος wrote:> Hello, as you all know i'am using cgi method for my web script.
>>
>> I have been told that webpy is the way to go sor script simple enough as
>> mines.
>>
>> Can you please show me the simplest example you can think of utilizing a
>> templates (index.html) and a python script (metrites.py) ?
>>
>> I want to see if it is easy to ditch cgi and pass to the world of web
>> frameworks.
>
> I don't know anything about webpy so I can help with that.
>
> But I did want to say that you can use templates without
> using a web framework like webpy.  They are very useful
> even with cgi code and can simplify the cgi code a lot.
>
> For my web server stuff (relatively small sites with low
> traffic) cgi is fine (simple, easy to debug, lots of online
> documentation and help) so I don't buy the "cgi is dead"
> comments seen frequently here.

Exactly my sentiments. As you know my webiste is http://superhost.gr
I write my html templates in notepad++ and then i use 'metrites.py' 
script as a means of opening my html templates and substitute spcial 
variables of html files with the onces being calculated within my python 
script, foe xample every html file of mine bottom down has its own page 
counter.

Ill give an example.

This is a part of my index.html template:

===================================
<div align=center><br><br><br>
	<font color=white size=4>
		Οι servers τρέχουν Linux και ο χειρισμός του λογαριασμού χρήστη 
γίνεται μέσω του cPanel.<br>
		Eδρεύουν στο Houston του Texas, σε ένα απο τα πιο αξιόπιστα - ταχύτατα 
DataCenters της Αμερικής.<br>
		Ζητείστε να σας ανοίξω δοκιμαστικό λογαριασμό μιας εβδομάδας προς 
αξιολόγηση της ποιότητας υπηρεσιών!<br>
	<font color=gold size=4> <b><i> %s </i></b> <br><br><br>

	<img src="/data/images/hosting.png">
	<img src="/data/images/design.png"><br>

	<audio controls autoplay="autoplay">
		<source src="/data/music/%s" type="audio/mp3">
	</audio>
</div><br><br>
===================================

and this being the part of the code of metrites.py that substitute the 
'%s' special variables with the actual data.

======================================
# pick a random mp3 from the the music directory
quote = random.choice( list( open( 
'/home/nikos/www/data/private/quotes.txt', encoding='utf-8' ) ) )
# pick a random line from the quote text file
music = random.choice( os.listdir( '/home/nikos/www/data/music/' ) )
======================================


Now with the help of an .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/metrites.py?file=%{REQUEST_FILENAME} 
[L,PT,QSA]

Every request of an html file on superhost.gr is being redirected into 
metrites.py script which make the substitution insde the html 
templates(yes in one python script but it can handle all my html files 
form within)

This is the simplest idea of web frameworking (if i can call it like that)

Now, if you can find me a better way of what i have actually descri bed 
i will ditch cgi and use your method. Personally i believe a more easy 
method from what i demonstrated cannot possibly .exist.


Thank you.

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

[toc] | [prev] | [next] | [standalone]


#49008

Fromrurpy@yahoo.com
Date2013-06-23 15:29 -0700
Message-ID<6624335b-0db7-48d8-897c-be7c960a253b@googlegroups.com>
In reply to#48984
On 06/23/2013 09:15 AM, Νίκος wrote:
> Στις 23/6/2013 5:57 μμ, ο/η rurpy@yahoo.com έγραψε:
>> On 06/23/2013 07:01 AM, Νίκος wrote:
> Hello, as you all know i'am using cgi method for my web script.
>>>
>>> I have been told that webpy is the way to go sor script simple enough as
>>> mines.
>>>
>>> Can you please show me the simplest example you can think of utilizing a
>>> templates (index.html) and a python script (metrites.py) ?
>>>
>>> I want to see if it is easy to ditch cgi and pass to the world of web
>>> frameworks.
>>
>> I don't know anything about webpy so I can help with that.
>>
>> But I did want to say that you can use templates without
>> using a web framework like webpy.  They are very useful
>> even with cgi code and can simplify the cgi code a lot.
>>
>> For my web server stuff (relatively small sites with low
>> traffic) cgi is fine (simple, easy to debug, lots of online
>> documentation and help) so I don't buy the "cgi is dead"
>> comments seen frequently here.
> 
> Exactly my sentiments. As you know my webiste is http://superhost.gr
> I write my html templates in notepad++ and then i use 'metrites.py' 
> script as a means of opening my html templates and substitute spcial 
> variables of html files with the onces being calculated within my python 
> script, foe xample every html file of mine bottom down has its own page 
> counter.
> 
> Ill give an example.
>[...snip...]
> Every request of an html file on superhost.gr is being redirected into 
> metrites.py script which make the substitution insde the html 
> templates(yes in one python script but it can handle all my html files 
> form within)
> 
> This is the simplest idea of web frameworking (if i can call it like that)
> 
> Now, if you can find me a better way of what i have actually descri bed 
> i will ditch cgi and use your method. Personally i believe a more easy 
> method from what i demonstrated cannot possibly .exist.

Firstly, I wrote:
>> I don't know anything about webpy so I can help with that.
I meant, I don't know anything about webpy so I *can't* help 
with that.  (Just in case it wasn't obvious.)

The option I mentioned was continue using cgi (but using a web 
templates package instead of your own), not to ditch cgi.  You 
would be ditching cgi if you switch to a web framework.  I was
saying that you don't have to use a web framework to use a web 
template package.

The advantage of using an already-developed web template package
is that it will have a lot more features and capabilities than 
your current way.  The disadvantage is that it will take some time
to learn to use it; you already know how to use your own template 
system.

If you do want to look into using a template package you'll need 
to pick one.  There is list of them with some info in each, here:
  http://wiki.python.org/moin/Templating?highlight=%28templates%29

Mako templates is a very popular package and since I've played
with it a little, I'll use it as an example.

Your template would look almost the same.  Instead of using Python's
%s string formatting, you would use Mako's rules for substitutions.
For simple variable they use ${variablename}.

> ===================================
> <div align=center><br><br><br>
> 	<font color=white size=4>
> 		Οι servers τρέχουν Linux και ο χειρισμός του λογαριασμού χρήστη 
> γίνεται μέσω του cPanel.<br>
> 		Eδρεύουν στο Houston του Texas, σε ένα απο τα πιο αξιόπιστα - ταχύτατα 
> DataCenters της Αμερικής.<br>
> 		Ζητείστε να σας ανοίξω δοκιμαστικό λογαριασμό μιας εβδομάδας προς 
> αξιολόγηση της ποιότητας υπηρεσιών!<br>
> 	<font color=gold size=4> <b><i> ${thequote} </i></b> <br><br><br>
> 
> 	<img src="/data/images/hosting.png">
> 	<img src="/data/images/design.png"><br>
> 
> 	<audio controls autoplay="autoplay">
> 		<source src="/data/music/${mp3file}" type="audio/mp3">
> 	</audio>
> </div><br><br>
> ===================================

and your code that gets values to substitute would be the same:

> ======================================
> # pick a random mp3 from the the music directory
> quote = random.choice( list( open( 
> '/home/nikos/www/data/private/quotes.txt', encoding='utf-8' ) ) )
> # pick a random line from the quote text file
> music = random.choice( os.listdir( '/home/nikos/www/data/music/' ) )
> ======================================

But instead of opening and reading index.html yourself, you use 
Mako to read it:

  template = mako.template.Template (filename='templates/index.html')
    
and then use Mako to do the substitutions:

  html = template.render (thequote=quote, mp3file=music)
  print (html)

"thequote" and "mp3file" are the variable names used inside the 
template.  "quote" and "music" are of course the variable names
yuo use in your python code.

In this simple example, there is not much advantage of Mako
over your templates.  But with more complicated cases, for
instance, when you have tables or forms that you want to 
dynamically construct from external data (info extracted
from a database for example) then a template system like Mako 
makes your Python code simpler because all the table and form '
stuff is in the template file, and all the Python code has to 
do is get the data and pass it to the template's render method.

For example, for a web page that shows a table of users and
their last login dates, your template might contain something
like

   <table> 
      <tr><th>Username</th>  <th>Last Login</th></tr>
      %for user,llog in userrecs:
        <tr><td>${user}</td>  <tr><td>${llog}</td></tr>
      %endfor
   </table>

And your Python cgi code

  userdata = mysqlcursor.execute (
    "SELECT username,MAX(logintime) FROM userlogins GROUP BY username", [])
  html = template.render (userrecs=userdata)
  print (html)

When you call template.render() above, Mako and the template 
will create an html table row for each user in userdata.

All code above is untested and from memory so there is probably 
errors in it.  I was just trying to give you an idea of how
template systems can make cgi code simpler without moving 
everything to a full web framework.

[toc] | [prev] | [next] | [standalone]


#49023

FromΝίκος <nikos@superhost.gr>
Date2013-06-24 04:44 +0300
Message-ID<kq889f$vnl$1@news.grnet.gr>
In reply to#49008
Στις 24/6/2013 1:29 πμ, ο/η rurpy@yahoo.com έγραψε:
> In this simple example, there is not much advantage of Mako
> over your templates.  But with more complicated cases, for
> instance, when you have tables or forms that you want to
> dynamically construct from external data (info extracted
> from a database for example) then a template system like Mako
> makes your Python code simpler because all the table and form '
> stuff is in the template file, and all the Python code has to
> do is get the data and pass it to the template's render method.
>
> For example, for a web page that shows a table of users and
> their last login dates, your template might contain something
> like
>
>     <table>
>        <tr><th>Username</th>  <th>Last Login</th></tr>
>        %for user,llog in userrecs:
>          <tr><td>${user}</td>  <tr><td>${llog}</td></tr>
>        %endfor
>     </table>
>
> And your Python cgi code
>
>    userdata = mysqlcursor.execute (
>      "SELECT username,MAX(logintime) FROM userlogins GROUP BY username", [])
>    html = template.render (userrecs=userdata)
>    print (html)
>
> When you call template.render() above, Mako and the template
> will create an html table row for each user in userdata.

I see. if for example i take my files.py where it acts like a template 
and python script all together and its in fact displaying not usernames 
but constructs an html table form extracted from database info, why you 
mako's approach and not keep it as i have it now which is:


# 
=================================================================================================================
# Display ALL files, each with its own download button
# 
=================================================================================================================
print('''<body background='/data/images/star.jpg'>
		 <center><img src='/data/images/download.gif'><br><br>
		 <table border=5 cellpadding=5 bgcolor=green>
''')

try:
	cur.execute( '''SELECT * FROM files ORDER BY lastvisit DESC''' )
	data = cur.fetchall()
	
	for row in data:
		(filename, hits, host, lastvisit) = row
		lastvisit = lastvisit.strftime('%A %e %b, %H:%M')
		
		print('''
		<form method="get" action="/cgi-bin/files.py">
			<tr>
				<td> <center> <input type="submit" name="filename" value="%s"> </td>
				<td> <center> <font color=yellow size=5> %s </td>
				<td> <center> <font color=silver size=4> %s </td>
				<td> <center> <font color=orange size=4> %s </td>
			</tr>
		</form>
		''' % (filename, hits, host, lastvisit) )
	print( '''</table><br><br>''' )
except pymysql.ProgrammingError as e:
	print( repr(e) )

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.


> All code above is untested and from memory so there is probably
> errors in it.  I was just trying to give you an idea of how
> template systems can make cgi code simpler without moving
> everything to a full web framework.

And if we wanted to to compare an html template method to a web 
framework solution?

What are the benefits of one over the other?

I know you dont use the latter but this questios is for averybody that does.


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

[toc] | [prev] | [next] | [standalone]


#49029

FromMichael Torrie <torriem@gmail.com>
Date2013-06-23 22:37 -0600
Message-ID<mailman.3738.1372048685.3114.python-list@python.org>
In reply to#49023
On 06/23/2013 07:44 PM, Νίκος wrote:
> 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.

> And if we wanted to to compare an html template method to a web 
> framework solution?

A web framework gives you database abstractions so you can easily target
most SQL servers without changing code (MySQL, MS SQL, PostgreSQL,
Oracle, etc), and they also provide frameworks for doing authentication
and authorization.  Authorization in particular becomes unwieldy quickly
if you have to do it all in CGI.  With a framework it's relatively easy
to decorate a view with a wrapper that can only allow the view to be
displayed if a web client has logged in with a particular set of
permissions (stored in your user database of coures).

> What are the benefits of one over the other?

If you need to do user logins, a framework is going to become rather
essential, in my opinion.  At least if you need to support fine-grained
permissions, which is what most enterprise web apps require (at least
the ones I worked on).

> I know you dont use the latter but this questios is for averybody that does.

Personally I feel that a templating engine is essential for any web
development, CGI or not.  Mixing html and code leads to an
unmaintainable mess.

A framework is not essential, but often desired.  If you don't use a
framework, eventually you'll find yourself creating your own framework
in essence, though often not nearly as robustly or as flexibly.

[toc] | [prev] | [next] | [standalone]


#49030

Fromrusi <rustompmody@gmail.com>
Date2013-06-23 21:49 -0700
Message-ID<7dfac913-d39d-4aeb-8d93-f9ec8a9c1e92@googlegroups.com>
In reply to#49029
On Monday, June 24, 2013 10:07:57 AM UTC+5:30, Michael Torrie wrote:
> On 06/23/2013 07:44 PM, Νίκος wrote:
> 
> > 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.

Thats a well-known very widely used technology. Its called php

> 
> 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.

Some people find even a 2-way separation messy.
Here's 3-way http://www.kuwata-lab.com/kwartz/ (or is it 4? Dunno...)

[toc] | [prev] | [next] | [standalone]


#49038

FromΝίκος <nikos@superhost.gr>
Date2013-06-24 10:32 +0300
Message-ID<kq8sn6$hlr$1@news.grnet.gr>
In reply to#49029
Στις 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!

[toc] | [prev] | [next] | [standalone]


#49054

Fromrusi <rustompmody@gmail.com>
Date2013-06-24 08:51 -0700
Message-ID<3d4d5793-b3b2-4225-9ac6-6fbbfc3a74c4@googlegroups.com>
In reply to#49038
On Monday, June 24, 2013 1:02:51 PM UTC+5:30, Νίκος wrote:

> 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.

Every significant templating system has something for this
eg in mako
http://docs.makotemplates.org/en/latest/syntax.html#control-structures

The main thing to understand is this:
- When you use straight python, by default you are 'inside python' except when inside strings (inside prints) then you are 'inside html'

- When using a templating engine, by default you are inside html, except when you escape from html into python

[toc] | [prev] | [next] | [standalone]


#49176

Fromrurpy@yahoo.com
Date2013-06-25 11:00 -0700
Message-ID<eeff0fca-7fbc-47a3-bda4-23d57cb3f48a@googlegroups.com>
In reply to#49023
On 06/23/2013 07:44 PM, Νίκος wrote:> 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.

Good question.  Sometimes your way is best.

The main advantage of using templates is that the template contains 
only html (mostly) and the cgi code contains only python (mostly).

The idea is that you can look at the template and see only the 
kind of code (html) that affects how the page looks.  With some
template systems you can edit the template files with a html 
editor and do the page design visually.  Even in a text editor
it is usually easier to see the how the html "works" without
spurious stuff like code.

And when you look at the cgi code, you see only the Python code 
that is needed to get the variable data that is displayed in the
page without the distraction of a lot of html stuff.

[toc] | [prev] | [next] | [standalone]


#49178

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-06-25 14:53 -0400
Message-ID<mailman.3841.1372186393.3114.python-list@python.org>
In reply to#49176

[Multipart message — attachments visible in raw view] — view raw

On Tue, Jun 25, 2013 at 2:00 PM, <rurpy@yahoo.com> wrote:

> On 06/23/2013 07:44 PM, Νίκος wrote:> 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.
>
> Good question.  Sometimes your way is best.
>
> The main advantage of using templates is that the template contains
> only html (mostly) and the cgi code contains only python (mostly).
>
> The idea is that you can look at the template and see only the
> kind of code (html) that affects how the page looks.  With some
> template systems you can edit the template files with a html
> editor and do the page design visually.  Even in a text editor
> it is usually easier to see the how the html "works" without
> spurious stuff like code.
>
> And when you look at the cgi code, you see only the Python code
> that is needed to get the variable data that is displayed in the
> page without the distraction of a lot of html stuff.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I haven't tried webpy but I have used django.  django has a tutorial that
takes a couple of hours to set up and go through completely.  Its not just
reading, its hands on trying out a small website.  It gives a very good
understanding of what the framework offers, and how difficult (or easy!) it
is to use.  If webpy has a similar tutorial, I would start there, or try
django.  After the tutorial, the discussion becomes a lot more concrete and
less theoretical as to whether that platform would be helpful

-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#49230

FromΝίκος <nikos@superhost.gr>
Date2013-06-26 08:31 +0300
Message-ID<kqdubr$t6$1@news.grnet.gr>
In reply to#49178
Στις 25/6/2013 9:53 μμ, ο/η Joel Goldstick έγραψε:

> I haven't tried webpy but I have used django.  django has a tutorial
> that takes a couple of hours to set up and go through completely.  Its
> not just reading, its hands on trying out a small website.  It gives a
> very good understanding of what the framework offers, and how difficult
> (or easy!) it is to use.  If webpy has a similar tutorial, I would start
> there, or try django.  After the tutorial, the discussion becomes a lot
> more concrete and less theoretical as to whether that platform would be
> helpful

Yes, because at the time being i really dont seem to even have a lcue of 
what i web framework is and how it si compred to python cgi or to other 
templating systems(mako)

I mean if its htere to make my life and scripts easier to maintain then 
i should use it, but if its gonna make my scripts more compilcated then 
i dont wish to use it. i tired to read some examples of webpy and django 
but i didnt understand them at all.

Also i saw some youtube videos but i just dont grasp their philosophy 
and why they are being used.

Thats why i hate docs they always leave me messed up and my basic 
questions unanswered.



What is now proved was at first only imagined!

[toc] | [prev] | [next] | [standalone]


#49322

FromΝίκος <nikos@superhost.gr>
Date2013-06-27 16:32 +0300
Message-ID<kqheso$31v$1@news.grnet.gr>
In reply to#49176
Στις 25/6/2013 9:00 μμ, ο/η rurpy@yahoo.com έγραψε:
> On 06/23/2013 07:44 PM, Νίκος wrote:> 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.
>
> Good question.  Sometimes your way is best.
>
> The main advantage of using templates is that the template contains
> only html (mostly) and the cgi code contains only python (mostly).
>
> The idea is that you can look at the template and see only the
> kind of code (html) that affects how the page looks.  With some
> template systems you can edit the template files with a html
> editor and do the page design visually.  Even in a text editor
> it is usually easier to see the how the html "works" without
> spurious stuff like code.
>
> And when you look at the cgi code, you see only the Python code
> that is needed to get the variable data that is displayed in the
> page without the distraction of a lot of html stuff.

I still cant make up my mind what i'm to use.

a) keep my existing Python cgi way that embed print ''' statements 
within python code to displays mostly tables?

b) use a mentioned html templating schema like i.e. mako?

c) use a micro web framework like flask?

Can someone please provide simple example of (b) and (c) to help me 
realizes the differences of html tamplates compared to frameworks?

Because the latter is still unclear to me as to what exactly is and 
behave so i cant tell if i'm to use it or not.


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

[toc] | [prev] | [next] | [standalone]


#49351

FromCameron Simpson <cs@zip.com.au>
Date2013-06-28 09:08 +1000
Message-ID<mailman.3944.1372375987.3114.python-list@python.org>
In reply to#49322
On 27Jun2013 16:32, Νίκος <nikos@superhost.gr> wrote:
| a) keep my existing Python cgi way that embed print ''' statements
| within python code to displays mostly tables?

I'd argue against this approach. Like hand constructing SQL, this
is rife with opportunity to make syntax errors, either outright by
mistyping HTML or accidentally by badly escaping content that is
not supposed to be HTML but happens to contain HTML marker characters
like "<".

When I generate HTML I usually make a structure of lists and dicts
that gets converted to HTML. Someone doing a nontrivial amount of
HTML would use a templating system of some kind I imagine; I don't
generate HTML very often.

Pick a simple framework or templating engine and try it. I have no
recommendations to make in this area myself.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

I'm behind a corporate Exchange Server which seems to have            
changed recently to converting everything it sees to HTML.             
How embarrassing. - Dan Espen <despen@telcordia.com>

[toc] | [prev] | [next] | [standalone]


#49359

FromΝίκος <nikos@superhost.gr>
Date2013-06-28 06:38 +0300
Message-ID<kqj0gj$3ro$1@news.grnet.gr>
In reply to#49351
Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:
> On 27Jun2013 16:32, Νίκος <nikos@superhost.gr> wrote:
> | a) keep my existing Python cgi way that embed print ''' statements
> | within python code to displays mostly tables?
>
> I'd argue against this approach. Like hand constructing SQL, this
> is rife with opportunity to make syntax errors, either outright by
> mistyping HTML or accidentally by badly escaping content that is
> not supposed to be HTML but happens to contain HTML marker characters
> like "<".
>
> When I generate HTML I usually make a structure of lists and dicts
> that gets converted to HTML. Someone doing a nontrivial amount of
> HTML would use a templating system of some kind I imagine; I don't
> generate HTML very often.
>
> Pick a simple framework or templating engine and try it. I have no
> recommendations to make in this area myself.

Can you explain to me the difference of the former and latter?

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

[toc] | [prev] | [next] | [standalone]


#49364

FromRobert Kern <robert.kern@gmail.com>
Date2013-06-28 10:35 +0100
Message-ID<mailman.3953.1372412165.3114.python-list@python.org>
In reply to#49359
On 2013-06-28 04:38, Νίκος wrote:
> Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:

>> Pick a simple framework or templating engine and try it. I have no
>> recommendations to make in this area myself.
>
> Can you explain to me the difference of the former and latter?

A templating engine takes your data and applies it to templates that you have 
written to generate the final HTML that is sent to the web browser.

A web framework is a library that provides tools and a way of structuring your 
that makes it easier to write a web application. Web frameworks typically 
include a templating engine or provide support for working with external 
templating engines. In addition, web frameworks provide many other services, 
like routing URLs to specific parts of your code, managing pools of database 
connections, handling web sessions, validating form data, and connecting your 
code to many different ways of deploying web applications without having to 
rewrite your code.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

[toc] | [prev] | [next] | [standalone]


#49365

FromΝίκος <nikos@superhost.gr>
Date2013-06-28 13:15 +0300
Message-ID<kqjnnv$mrl$1@news.grnet.gr>
In reply to#49364
Στις 28/6/2013 12:35 μμ, ο/η Robert Kern έγραψε:
> On 2013-06-28 04:38, Νίκος wrote:
>> Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:
>
>>> Pick a simple framework or templating engine and try it. I have no
>>> recommendations to make in this area myself.
>>
>> Can you explain to me the difference of the former and latter?
>
> A templating engine takes your data and applies it to templates that you
> have written to generate the final HTML that is sent to the web browser.
>
> A web framework is a library that provides tools and a way of
> structuring your that makes it easier to write a web application. Web
> frameworks typically include a templating engine or provide support for
> working with external templating engines. In addition, web frameworks
> provide many other services, like routing URLs to specific parts of your
> code, managing pools of database connections, handling web sessions,
> validating form data, and connecting your code to many different ways of
> deploying web applications without having to rewrite your code.

I see, your explanation started to make things clearer to me.
What is the easiest and simplest web framework you advise me to use?

Also please provide a well written and simple tutorial i can read upon.
Thank you.

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

[toc] | [prev] | [next] | [standalone]


#49367

FromRobert Kern <robert.kern@gmail.com>
Date2013-06-28 11:30 +0100
Message-ID<mailman.3954.1372415425.3114.python-list@python.org>
In reply to#49365
On 2013-06-28 11:15, Νίκος wrote:
> Στις 28/6/2013 12:35 μμ, ο/η Robert Kern έγραψε:
>> On 2013-06-28 04:38, Νίκος wrote:
>>> Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:
>>
>>>> Pick a simple framework or templating engine and try it. I have no
>>>> recommendations to make in this area myself.
>>>
>>> Can you explain to me the difference of the former and latter?
>>
>> A templating engine takes your data and applies it to templates that you
>> have written to generate the final HTML that is sent to the web browser.
>>
>> A web framework is a library that provides tools and a way of
>> structuring your that makes it easier to write a web application. Web
>> frameworks typically include a templating engine or provide support for
>> working with external templating engines. In addition, web frameworks
>> provide many other services, like routing URLs to specific parts of your
>> code, managing pools of database connections, handling web sessions,
>> validating form data, and connecting your code to many different ways of
>> deploying web applications without having to rewrite your code.
>
> I see, your explanation started to make things clearer to me.
> What is the easiest and simplest web framework you advise me to use?
>
> Also please provide a well written and simple tutorial i can read upon.
> Thank you.

I will not advise you to do anything. I will point you to a web framework that I 
happen to like, but you will need to read its documentation to decide if it is 
right for you. I cannot provide any help in installing or using it.

   http://flask.pocoo.org/
   http://flask.pocoo.org/docs/tutorial/

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

[toc] | [prev] | [next] | [standalone]


#49373

Fromrusi <rustompmody@gmail.com>
Date2013-06-28 07:28 -0700
Message-ID<136bfc77-f6a7-4bf8-a01c-3f5fb926c037@googlegroups.com>
In reply to#49365
On Friday, June 28, 2013 3:45:27 PM UTC+5:30, Νίκος wrote:
> Στις 28/6/2013 12:35 μμ, ο/η Robert Kern έγραψε:
> I see, your explanation started to make things clearer to me.
> What is the easiest and simplest web framework you advise me to use?
> 

Here's a picture of the web-development scene as I see it:

At one extreme there are mega-frameworks like django.
At the other one can write everything as you have been trying.

Both these can be unsatisfactory (as you are discovering!)

In between is a line which follows from Robert Kern's suggestions.

So my advise is to understand and follow these suggestions.  IOW take each of the items mentioned here (starting templating):

> > A web framework is a library that provides tools and a way of
> > structuring your that makes it easier to write a web application. Web
> > frameworks typically include a templating engine or provide support for
> > working with external templating engines. In addition, web frameworks
> > provide many other services, like routing URLs to specific parts of your
> > code, managing pools of database connections, handling web sessions,
> > validating form data, and connecting your code to many different ways of
> > deploying web applications without having to rewrite your code.

1. Now run a web-search for that.
2. See if it looks of any use to you
3. Check the available libraries
4. Install and try out* something that looks simple
5. When stuck -- either concepts or details -- come back here and ask

* Not on a live server!!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web