[Twisted-web] Turkey Questions 6-8
lloyd at paisite.com
lloyd at paisite.com
Fri Jul 8 14:33:51 MDT 2005
Thanks for responding.
I've started a website to capture the sequence of experiments, questions,
and responses. Will have posted this weekend.
> Presumably because you ran mktap from your home directory. The --path is
> the path to the root of the web server. The .tak file is written to the
> current directory.
>>2) Why didn't myHTML.html require a "Content-type: text/html" line?
> The web.tap you created actually uses a twisted.web.static.File instance
> to serve the files from the --path directory. static.File guesses the
> MIME type and sends the Content-Type response header to the browser.
I rarely use mktap. I find it useful
> for quickly creating a web server for static content but most of the
> stuff I use is highly dynamic.
> Here's an equivalent .tac file that serves static content:
> from twisted.application import internet, service
> from twisted.web import server, static
> WWWROOT = '/home/matt/www/docs'
> LOGPATH = '/home/matt/www/logs/access.log'
> PORT = 8080
> application = service.Application('web-server')
> site = server.Site(static.File(WWWROOT), logPath=LOGPATH)
> internet.TCPServer(PORT, site).setServiceParent(application)
I copied and saved this code to web.tac. Then tried to launch it with
twistd -ny web.tac.
System came back with response: Failed to load application: TCPServer has
no attribute 'setServerParent'
I looked at source for twisted.application.internet, which seems to import
new to synthesize TCPServer. Couldn't follow from there because I didn't
have time to track down new.
Question 6: Why did this code fail?
Question 7: Where is new?
> That sort of thing can be easily modified into something that creates a
> dynamic root resource.
This is the line I'd like to pursue next. I'll see how far I can go on my
own, then come back when stuck.
> I never use .rpy resources so all my Python is in packages and modules.
> I tend to have templates, css, js and images in a directory somewhere
> and a .tac to start the services.
Question 8: What's wrong with .rpy resources?
> Site data is either in a database or in another directory, away from the
> templates etc.
> Well, I think the most important thing is to avoid making *any* code or
> data directly accessible from the web. That's fairly easy to do if you
> don't use .rpy files and make sure that any directories served by
> static.File resources don't contain any files with sensitive content.
> XHTML templates should not be directly accessible over the web either.
Again, thanks for you help, Matt.
More information about the Twisted-web