Hi,
I need to create a planner/calendar system using python cgi scripts. It
is my first CGI app (beyond a few tutorial examples).
I wish to separate the code according to function. For instance, the
code to handle the DB connection, SQL querying, HTML form variable
retrieval, rendering of HTML via some sort of template system etc. Each
will be a class instantiated when the CGI app is called.
To do this, do I just create each of these classes in one, monolithic
..cgi file? or is it possible to separate these out into different
scripts and have a 'controller' script call them and pass the relevant
parameters/data? I guess I could also store the python code in text
files and use the 'execfile()' function, although it seems to me that
would be an uneccasary performance hit.
If that is possible, is that the right way to go? If not, suggestions
would be gratefully recieved! 6 1413
Rob Cowie enlightened us with: I need to create a planner/calendar system using python cgi scripts. It is my first CGI app (beyond a few tutorial examples).
Are you sure you want to use CGI? I'd go for mod_python instead if at
all possible, since that'll give you a much better performance.
To do this, do I just create each of these classes in one, monolithic .cgi file?
Please don't. It's much better to put things into modules, and import
them when needed.
or is it possible to separate these out into different scripts and have a 'controller' script call them and pass the relevant parameters/data? I guess I could also store the python code in text files and use the 'execfile()' function, although it seems to me that would be an uneccasary performance hit.
Why that difficult? What's wrong with just doing "from htmlgenerator
import pagexy"?
If that is possible, is that the right way to go? If not, suggestions would be gratefully recieved!
Check out http://www.unrealtower.org/mycheetah
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
So, do I separate out whatever code I want to into .py modules, then
have the cgi script import them, and utilise them as required?
If so, do I need to put these modules somewhere described in the System
Path? Can I modify the PATH at runtime to point to my modules? How?
Cheers for being patient!
Rob Cowie wrote: So, do I separate out whatever code I want to into .py modules, then have the cgi script import them, and utilise them as required?
Bingo!
If so, do I need to put these modules somewhere described in the System Path?
Put them in the same directory, and you don't have to worry any more
about it. You can get more advanced if you want by putting your modules
into a "package", which is just a directory with a __init__.py file -
see the docs at python.org.
Can I modify the PATH at runtime to point to my modules? How?
If you want to have them in a different directory, and the directory
isn't already in sys.path, then just issue, from your main script,
before your import statements:
import sys
sys.path.insert(0, "/path/to/your/modules")
Cheers for being patient!
Welcome to Python! Being new to it, you may want to consider having
someone review your code before putting it on the public internet,
simply because there are lots of opportunities for inadvertantly
providing backdoors (Python is powerful). This is especially true if you
let your users type into a text box, or if you do dynamic database
queries, or both.
Also, have you run through the tutorial on python.org?
--
Paul McNett http://paulmcnett.com
Thanks,
I have run through the tutorial - very good. One day, I'd like to try
and organise a similar tutorial involving CGI programming. There are
several very basic examples, but they leave plenty of unanswered
questions such as how to best structure a cgi app, apache permissions,
etc
So to be clear, if a .py module is in the same directory as my python
cgi script, I can import it thus 'import XXX.py'?
Rob Cowie wrote: So to be clear, if a .py module is in the same directory as my python cgi script, I can import it thus 'import XXX.py'?
Not quite. If you had a XXX.py, XXX.pyc, and/or XXX.pyo in the same
directory as your Python cgi script, you'd import it by issuing:
import XXX
--
Paul McNett http://paulmcnett.com
Rob Cowie a écrit : Hi,
I need to create a planner/calendar system using python cgi scripts. It is my first CGI app (beyond a few tutorial examples).
(snip)
You may want to have a look at the cgi_app mini-framework:
-> http://thraxil.org/code/cgi_app/
It's a port of a Perl framework, and it has some unpythonic flavour in
some points (but that can be easily corrected), and it can work with CGI
and mod_python. It's quite easy to get started with, and the source
being really small (about 1kloc IIRC), it's quite easy to customize to
your own needs (I rolled my own mod_python-only/SimpleTAL-only version
in half a day...).
You also have the choice between 2 template systems, one that's dirty as
can be IMHO (htmltmpl) and one that is quite nice (SimpleTAL). The only
wart with SimpleTAL is that it requires every input to be unicode, but
that's easy to solve also (I wrote a wrapper class that handle this
quite transparently - it's still Q&D but works well so far, I can
publish it if anyone is interested).
My 2 cents This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eric Veltman |
last post by:
Hello everyone,
I've posted this question before, but got no answer,
so I'll try to reformulate the question, maybe it helps :-)
By the way, this is not intended as the start of an ASP.NET...
|
by: Droolboy |
last post by:
I'm trying to build a fairly small (max. 10 different pages) site
using php, and it's becoming obvious that I need some kind of model
view separation.
Having done a few searches, I've come...
|
by: Griff |
last post by:
Hi there
I'm after some suggestions as to how one might best separate form and
content in a normal run-of-the-mill web application. I'm sure whole
bookshelves have been written on this, but I...
|
by: Dave |
last post by:
Hi,
I currently have the following in order to have a little bit of
horizontal spacing separation between the bullet images and the text
in the list (and I'm happy with the vertical separation...
|
by: Sandeep Raje |
last post by:
By default, when I start a paragraph, I get white space before the
paragraph. What CSS property can I use to conrol the white space created
before the paragraph. In particular, I would like to...
|
by: Michael |
last post by:
Hi,
I'm using Visual Studio 2005 RTM.
After reading some articles about ASP.NET beta1 & beta2,
I'm confused...
Q1: Is the default coding mode Inline code?
Q2: How many .DLLs will be...
|
by: Jon Maz |
last post by:
Hi,
I'm facing a code-optimisation issue on an asp.net/vb.net/SQL Server 2000
project. A web page containing not much more than 3 DropDownLists is taking
nigh on 6 seconds to load, because each...
|
by: noone |
last post by:
Hi.
I've got a fella working for me who is trying to convince me to change our
coding standards to using separate .h and .cc files for definitions and
implementations. I know this is a...
|
by: Frank van Wensveen |
last post by:
Friend, coders, fellow wage slaves, lend my your ears.
I believe that in a perfect world the design of a website (or feature
on a website) should be totally separated from its design and the data...
|
by: Dormilich |
last post by:
Hi Folks,
content–code separation is a paradigm many of us know (well, I hope so at least). so my question is: which way do you prefer?
the absolute way:
<?php
function makeContent() { /* …...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |