Στις 23/6/2013 5:57 μμ, ο/η ru...@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!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to