StaticGenerator for Django Updated (1.3.1)
June 3, 2008
Version 1.3.1 of StaticGenerator is out. You can now get it using easy_install:
$ sudo easy_install staticgenerator
Note that the module name has changed. Instead of importing from generator you import from staticgenerator.
# Old Way
from generator import quick_publish
# New Way
from staticgenerator import quick_publish
The Big News
Now StaticGenerator leverages Django’s awesome Middleware system to more efficiently create the static files. Just add the Middleware class to settings.py and add a STATIC_GENERATOR_URLS setting like so (You must place the StaticGeneratorMiddleware before FlatpageFallbackMiddleware if you use it.):
MIDDLEWARE_CLASSES = (
...snip...
'staticgenerator.middleware.StaticGeneratorMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
...snip...
)
STATIC_GENERATOR_URLS = (
r'^/$',
r'^/(blog|about|projects)',
)
This way it creates the cache when it’s first displayed, solving the “404 problem”. Read more about this at the project page.
And let me know what you think!
Update: I modified the example URLs to show better efficiency.
Add your comment
No HTML; Only URLs and line breaks are converted.
Comments
It seems a bit awkward to include URLs twice (even though it allows you to be more explicit about which ones you're caching). Would an extension to urls.py (via a decorator or similar) be more elegant?
@static_generate
urlpatterns = patterns('',
url(r'^$', views.hub, name="hub"),
)
Posted by Brad Wright
The StaticGenerator URLs will generally be different than your urls.py. Part of the reason is you might simply want to include everything under blog, so you only have to add
r'^/blog'
Whereas your urls.py likely has many lines with archive_dates, etc. It's much less expensive to have a separate set of URLs for StaticGenerator, and it can be consolidated considerably:
STATIC_GENERATOR_URLS = (
r'^/(blog|about|projects)'
)
Posted by SuperJared
SuperJared, you rock! I was just thinking about giving Static Generator a shot and here you come out with an update. Thanks!
Posted by Billbot
at rev. 8015, request.path became request.path_info. making this change on line 108 of staticgenerator/__init__.py gets staticgenerator going again. w/o the change (or using an older rev. of django trunk) leads to a rather confusing "NoneType is not iterable" in django.core.handlers.base.BaseHandler.
Posted by matt dennewitz