[Twisted-Python] Dynamic web application using twisted.web.resource
Mukhsein Johari
arashi1 at pd.jaring.my
Tue Jul 30 12:19:39 EDT 2002
Hello fellow twisters,
This is a question (albeit a long one) directed at twisted.web and resource.
The project:
I would like to serve a dynamic website using the twisted web server. I
understand that the webserver's 'root' directory can be set at a file? I may
have a misunderstanding of the code and docs but if so, feel free to set me
straight.
The website (not real):
http://www.mywebsite.com/
This is the root of the site, which is in reality a erm..rpy? program? Which
means that there are _no_ static pages at all. And no other 'file' -
everything goes through that .rpy file. (or whatever else I should be using)
In a browser, entering this would get a dynamically 'constructed' page which
is in fact:
myobject.index()
From here on, something like:
http://www.mywebsite.com/projects/project_ako
would actually be (in the code) something like:
myobject.projects["project_ako"].index(myvar=None)
which returns an html page suitable for the browser's consumption.
On the other hand this:
http://www.mywebsite.com/projects/project_ako?myvar=bold
(for http GET. POST should be handled as well...how? I am guessing the request
object?)
Would call:
myobject.projects["project_ako"].index(myvar='bold')
Any other subobject of project_ako would 'call' a method on that object.
So for:
http://www.mywebsite.com/projects/project_ako/getSize
Would call:
myobject.projects["project_ako"].getSize()
The return value being sent back to the browser. Calls to non-existing methods
get a "No such method or object" error returned - formatted, of course.
The question is of course, how do you differentiate between an object and a
method? This is done by the application itself. It would check to see if that
object has a method with that name, if not check to see if it has a child
object with that name. Else return error.
The thing is, I know I need to use twisted.web.resource but I'm not sure
_how_. How does this fit in with the .rpy file? I think I need to create my
modules and classes and then create an .rpy which acts as the
erm..'interface' to the modules and classes. Could someone give me some hints
and tips?
Conceptually, it's quite simple but I can't seem to figure out how to do it
with twisted...Anyway, thanks for any help, in advance.
--
Regards,
Mukhsein Johari
More information about the Twisted-Python
mailing list