[Zope] Constructing 'Friendly' URLs in products

Tino Wildenhain tino at wildenhain.de
Thu Dec 2 14:20:15 EST 2004


Hi,

Am Donnerstag, den 02.12.2004, 15:52 +1300 schrieb Phillip Hutchings:
> Hi,
> 
> I'm fairly new to Zope, so if it's a obvious answer don't kill me ;)
> 
> I've been considering setting up a blog in Zope. I used to use
> Wordpress in PHP before I decided to give Zope a try, and I'm actually
> liking it so far.
> 
> Anyway, I've looked at coreblog, but it gives URLs like /blog/12 and
> /blog/1234, I'm really looking for things like
> /blog/2004/11/04/wow-zope-is-cool, like Wordpress manages with the aid
> of mod_rewrite.
> 
> Now, I guess I could do somthing like
> /blogposts?year=2004&month=11&day=04&title=wow-zope-is-cool through
> mod_rewrite, but I was wondering if there was a more zope-centric
> solution? About the best I could come up with was chaining a series of
> persistant classes which subclass Item.Folder (iirc that's the one),
> sort of like this:
> Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool),
> just a containment hierarchy. Is this good or bad thinking? I was also
> thinking of a single class that used something like __getattr__ to
> process a function or something, but I haven't though of how that
> would work. Probably like this myPosts =
> {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not
> sure if that would even work.
> 

The most easy way to do what you want is probably store your
blog entries somehow (for example in a btree2 folder - a 3rd
party product to improve handling of hundreds of thousands and
more objects) And use ZCatalog to index them based on some
properties.

make "blog" an python script object, try:

return traverse_subpath

(nothing more in this script)

now access it via:

/blog/foo/bar/wow-zope-is-cool

Try some self invented URLs and see what you get.

Now constructing search keys out of the URL parts
should be straigt forward (if you know a little python)

Hope these hints do help.

Regards
Tino



More information about the Zope mailing list