Hi Jannis, Thanks for your efford on staticfiles!
I guess the patch is okay, but I didn't review it in detail. Also a utility function in staticfiles for reading the actual content on the server side, giving a relative path would be nice if such one does not yet exist. e.g. from staticfiles.utils import staticfile_open filepointer = staticfile_open('my-relative-path...') Thanks, Jonathan On 8 août, 12:17, Jannis Leidel <lei...@gmail.com> wrote: > Hi all, > > I believe I'm getting close to a fix for #15252 which would add > a bunch of new features to the staticfiles contrib app. I'd > appreciated it if someone would review the latest patch at > > https://code.djangoproject.com/ticket/15252 > > ``static`` template tag > ----------------------- > > The purpose of the template tag is to make it easier to refer > to static files from templates while extending the possibilities > at the same time. So instead of relying on a context variable > named ``STATIC_URL`` you could alternatively use the new template > tag with a relative path of a file you want the URL for, e.g.: > > {% static "css/base.css" %} > > Behind the scenes it uses the configured storage backend that > staticfiles uses when you run collectstatic (STATICFILES_STORAGE), > which means it's also works with non-local storage backends, > such as one that deploys to a private Amazon S3 bucket which > requires using signed URLs to access a file. > > In other words, it allows a much richer API to building the URL > of a static file by using the storage API that is already in place. > > CachedStaticFilesStorage > ------------------------ > > The second feature is an optional storage backend which hooks > right into the new template tag and is a subclass of the default > StaticFilesStorage (which is a subclass of FileSystemStorage). > It basically adds "cache-busting" abilities to staticfiles. > > Specifically, when enabled and you run collectstatic it saves > a second version of each file it finds, only with a MD5 hash > appended to the filename, which is generated with its own content. > So if a ``css/base.css`` would be collected, it would also deploy > a ``css/base.27e20196a850.css``. Any CSS @import and url() > statements are automatically replaced with the cached path in > those cached files, too. > > Later, when the ``static`` template tag tries to create the URL > for ``css/base.css``, it will use the same code path to return the > URL to the cached file instead. To lower the burden of calculating > the MD5 hash, the result is cached in an own cache backend named > "staticfiles" (falls back to "default" if not specified in CACHES). > > I've written this functionality as a mixin (CachedFilesMixin), so it > should be possible to use it with any storage backend that supports > the common API (url(), open() and save()). > > I'd appreciate if you would test-drive the feature and let me know > if you find any big issues since I plan to merge this very soon. > > Thanks! > > Jannis -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.