473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Running CGI from within CGI

I am new to using Python as a CGI platform, so please excuse me if
this is a dumb question.

Anyway I have written a series of web forms (with Python scripts)
which allow the user input but also retrieve data from a database. The
data entry stage works fine however retrieving data is a little more
tricky. However I need to find a way to call the scripts directly from
within other CGI's. At present when I go to the next page I call the
normal HTML page as below:

p = open('somefile.html')
some = p.read()
p.close()
print some
However I would like to execute a script instead so calling for
example myscript.py - thus populating the existing forms with data.
This does not seem to work when I modify the above method. Is there
another way to do it? Thanks in advance.

Kind regards,

rod
Feb 14 '08 #1
2 1157
rodmc a écrit :
I am new to using Python as a CGI platform, so please excuse me if
this is a dumb question.

Anyway I have written a series of web forms (with Python scripts)
which allow the user input but also retrieve data from a database. The
data entry stage works fine however retrieving data is a little more
tricky. However I need to find a way to call the scripts directly from
within other CGI's. At present when I go to the next page I call the
normal HTML page as below:

p = open('somefile.html')
some = p.read()
p.close()
print some
However I would like to execute a script instead so calling for
example myscript.py - thus populating the existing forms with data.
This does not seem to work when I modify the above method. Is there
another way to do it? Thanks in advance.
The QuickAndDirtyWay(tm) would be to use execfile IIRC. But since you
*don't* want to do it that way, the best thing to do would be to factor
out common code into functions in a distinct module (or in as many
modules as needed), then rewrite your cgi scripts so they import the
relevant modules and call the appropriate functions.

And while we're at it, I'd greatly recommand giving a look at the
various templating packages around (may I recommand Mako ?) and the
FormEncode package for HTTP forms conversion/validation ?

HTH
Feb 14 '08 #2
Thanks for the details, is execfile full of security issues or
something?

You are right about exploring templates, I may explore that later.
However I need to integrate the forms in with another system, which
will not be using templates. I suspect I may have taken the long way
round but I suppose it also means I learn a little more Python :-)

Cheers,

rod

On Feb 14, 3:26 pm, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
rodmc a écrit :
I am new to using Python as a CGI platform, so please excuse me if
this is a dumb question.
Anyway I have written a series of web forms (with Python scripts)
which allow the user input but also retrieve data from a database. The
data entry stage works fine however retrieving data is a little more
tricky. However I need to find a way to call the scripts directly from
within other CGI's. At present when I go to the next page I call the
normal HTML page as below:
p = open('somefile.html')
some = p.read()
p.close()
print some
However I would like to execute a script instead so calling for
example myscript.py - thus populating the existing forms with data.
This does not seem to work when I modify the above method. Is there
another way to do it? Thanks in advance.

The QuickAndDirtyWay(tm) would be to use execfile IIRC. But since you
*don't* want to do it that way, the best thing to do would be to factor
out common code into functions in a distinct module (or in as many
modules as needed), then rewrite your cgi scripts so they import the
relevant modules and call the appropriate functions.

And while we're at it, I'd greatly recommand giving a look at the
various templating packages around (may I recommand Mako ?) and the
FormEncode package for HTTP forms conversion/validation ?

HTH


Feb 14 '08 #3

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

Similar topics

8
by: nickdu | last post by:
I'm trying to isolate "applications" into their own application domain within a single process. I've quoted applications because it's a logical representation of an application. Basically it...
10
by: ThunderMusic | last post by:
Hi, How can I get if the Windows running is a server version? Is there a property somewhere that can tell me if the Windows version is a server edition (including server, advanced server, web...
6
by: foldface | last post by:
Hi Sorry, don't know how to phrase the question any better. Within Visual Studio I have a style sheet that being dynamically added to the code, i.e. not via the html page. I want to place this...
6
by: Anders Both | last post by:
I want to run a application (console or window) in the asp.net process, because i need an running application on the server that can acces the same data/singleton object as my asp.net application....
2
by: Oenone | last post by:
I am developing an assembly that can be used either by a Windows Forms application or from within an ASP.NET web site. When running within the Forms app, I can break into the code while it is...
7
by: John Murtari | last post by:
Folks, We would like to upgrade our servers to PHP 5 and PHP 4 together as modules on the same server (not as cgi, not passing requests to another server). I did some extensive searching on...
0
by: jcunningham | last post by:
Hello. I am running Crystal Reports (CR) from within an Access DB. I need to be able to have CR point to the Access DB it resides in automatically. That is, the CR's reside in the database I...
7
by: =?Utf-8?B?U2hpdmEgUmFtYW5p?= | last post by:
I have a windows application with multiple forms & another web application. Now I need a parent EXE or Application which need to act as a container to these application. Example : My existing Web...
1
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= | last post by:
On reflection, you could possibly make the app a self extracting zip file which extracts the EXE and a settings file and then starts the app, then when you app closes, it can repack the settings...
20
by: Nates | last post by:
I have a .bas file saved locally that I load into my Acces project to run a particular sub. I use the following code to load the module (which works fine): I use the following loop to remove...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.