I seem to have a problem processing css files with twisted.web using twisted templates.<br><br><br>I get a message in my Firefox error console saying that it could not load the css file since the type was text/html not text/css<br>
<br>I am running on windows 7 32bit<br>python 2.7.3<br>twisted 12.2.0<br>twisted templates<br><br>The template renders fine but without the styling.<br><br>I
have hunted around for some ideas as to what the problem is but most
seem to be that people have not added the static file location to root.<br>
<br>In theory I do not have that problem since the message says it has
found the file but will not process it since it has the wrong type.<br><br>In
my template file I add the link for the css file and give it the
correct file type. But I assume I have overlooked something since it
refuses to process the css.<br>
<br>My template is based on one of the demo templates and I have really just added the css link<br><br><html xmlns:t="<a href="http://twistedmatrix.com/ns/twisted.web.template/0.1" target="_blank">http://twistedmatrix.com/ns/twisted.web.template/0.1</a>"><br>
<head><br><title><br>Add Admin User<br></title><br><link href="styles/jahstyle.css" rel="stylesheet" type="text/css" /><br></head><br><body><br><div t:render="header" /><br>
<ul><br><li t:render="widgets"><br><t:slot name="widgetName"/><br></li><br></ul><br><div t:render="footer" /><br></body><br></html><br><br><br>
The python that is processing this file is based on the samples I found with some additions to add the staic file for the css<br><br><br>from twisted.web.server import Site, NOT_DONE_YET<br>from twisted.web.resource import Resource<br>
from twisted.internet import reactor<br>from twisted.web import server, static<br><br>from twisted.web.template import Element, renderer, XMLFile, flattenString<br>from twisted.python.filepath import FilePath<br><br>class WidgetsElement(Element):<br>
loader = XMLFile(FilePath('iteration-1.xml'))<br><br> widgetData = ['gadget', 'contraption', 'gizmo', 'doohickey']<br><br> @renderer<br> def widgets(self, request, tag):<br>
for widget in self.widgetData:<br> yield tag.clone().fillSlots(widgetName=widget)<br><br> @renderer<br> def header(self, request, tag):<br> return tag('Header.')<br><br> @renderer<br>
def footer(self, request, tag):<br> return tag('Footer.')<br><br><br>def printResult(result):<br> print result<br><br>class Root(Resource):<br> isLeaf = True<br> def render_GET(self, request):<br>
request.write("<!DOCTYPE html>\n")<br> #flattenString(request, Hello()).addCallback(request.write)<br> flattenString(None, WidgetsElement()).addCallback(request.write)<br> request.finish()<br>
return NOT_DONE_YET<br><br>root = Root()<br>root.putChild('styles', static.File("styles"))<br>site = Site(root)<br>reactor.listenTCP(8080, site)<br>reactor.run()<br><br>So if anyone has some clues as to what I should look for next that would be very welcome.<br>
<br>Regards<br><br>John Aherne<br clear="all"><div><br></div>-- <br><b>John Aherne</b><div><b><br></b><div><b><img src="http://www.rocs.co.uk/Images/rocs_logo_sig.gif"><br></b></div><div><b><br></b></div><div><div><b><a href="http://www.rocs.co.uk" target="_blank">www.rocs.co.uk</a><br>
</b></div></div></div><div>020 7223 7567</div><br>