[Zope] Re: The best way
Tres Seaver
tseaver at palladion.com
Fri Jan 11 14:03:35 EST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Garito wrote:
> Hi, all!
> If you have download the ZSM product you could see I put on it a zexp
> file with prototype and some other js file and a css file plus images
>
> This was only a prototype solution to bring you the chance to see how
> my ideas are but I think this is not a definitive solution
>
> Now my question:
>
> Which is the best zope way to serve this kind of files trying to avoid
> any other product dependence?
>
> Thanks a lot!
In the context of Five / Zope3, the static content items are
"resources". One strategy would be to create a Zope2 product with those
files in a subdirectory, e.g.::
$ mkdir Products/garito
$ cd Products/garito
$ echo "# ZSM product" > __init__.py
$ mkdir static
$ cat > static/garito.css
body {
background: #CCCCFF;
}
^D
And then register that directory as a "resource directory" via ZCML::
$ cat > configure.zcml
<configure xmlns:browser="http://namespaces.zope.org/browser">
<browser:resourceDirectory
name="garito"
directory="static"
/>
</configure>
^D
Now, when you start Zope2, you can pull in your static resources via
special URLs, like http://localhost:8080/++resource++garito/garito.css::
$ cd ../..
$ bin/zopectl start
. daemon process started, pid=25240
$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /++resource++garito/garito.css HTTP/1.0
HTTP/1.0 200 OK
Server: Zope/(unreleased version, python 2.4.4, linux2) ZServer/1.1
Date: Fri, 11 Jan 2008 18:53:11 GMT
Content-Length: 32
Last-Modified: Fri, 11 Jan 2008 18:44:47 GMT
Connection: close
Cache-Control: public,max-age=86400
Content-Type: text/css; charset=iso-8859-15
body {
background: #CCCCFF;
}
Connection closed by foreign host.
In that product, you could also register a template / browser view which
includes your resources, e.g::
$ cd Products/garito
$ cat > garito.pt
<html>
<head>
<link rel="stylesheet" type="text/css"
href="/++resource++garito/garito.css"/>
</head>
<body>
<h1> Garito's view </h1>
</body>
</html>
^D
$ cat > configure.zcml
<configure xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
for="*"
name="garito.html"
template="garito.pt"
permission="zope2.View"
/>
<browser:resourceDirectory
name="garito"
directory="static"
/>
</configure>
^D
$ cd ../..
$ bin/zopectl restart
$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /garito.html HTTP/1.0
HTTP/1.0 200 OK
Server: Zope/(unreleased version, python 2.4.4, linux2) ZServer/1.1
Date: Fri, 11 Jan 2008 19:02:05 GMT
Content-Length: 151
Content-Type: text/html; charset=iso-8859-15
Connection: close
<html>
<head>
<link rel="stylesheet" type="text/css"
href="/++resource++garito/garito.css" />
</head>
<body>
<h1> Garito's view </h1>
</body>
</html>
Connection closed by foreign host.
Which pulls in your static resources.
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHh72H+gerLs4ltQ4RAgwwAKDSJPrGAuwo++ShjWjZzyn06IDz1QCeK69s
+CIbgsCJkbRV5Tdh9XWEY9k=
=Du8x
-----END PGP SIGNATURE-----
More information about the Zope
mailing list