This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Building Static Files

Sooner or later, you’re going to need to add a build step to your Django apps; whether it’s because of Sass, Less, Coffee, AMD, or just to optimize your PNGs and JPEGs. There are a few popular ways to do some of these things with Django, but each has its own specific goals, and you can easily find your build requirements outside of their scope. django-staticbuilder takes a different approach by giving you a simple way to add a build step to your workflow, but has absolutely no opinion about what that build step should be, making it easy to take advantage of whatever build tools you want.

Check out the full documentation on readthedocs.

The heart of the staticbuilder build step is the buildstatic management command, and it is stupid simple. In fact, it only does two things: first, it collects your static files into a build directory and, second, it runs some shell commands. (Seriously, look at the source. It delegates most of its work to Django’s collectstatic. And that’s A Good Thing.)

To get started, add staticbuilder to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'staticbuilder',
)

To specify the build directory, use the STATICBUILDER_BUILD_ROOT setting:

STATICBUILDER_BUILD_ROOT = os.path.join(os.path.dirname(__file__), 'static_built')

To specify a list of shell commands to run with the STATICBUILDER_BUILD_COMMANDS setting:

STATICBUILDER_BUILD_COMMANDS = [
    'coffee -c /path/to/build_dir',
    'uglifyjs /path/to/build_dir/a.js -c > /path/to/build_dir/a.js',
]

or (to keep things a little more tidy):

STATICBUILDER_BUILD_COMMANDS = ['./bin/mybuildscript']

Finally, you’ll need to add a special finder to your STATICFILES_FINDERS list:

STATICFILES_FINDERS = (
    'staticbuilder.finders.BuiltFileFinder',

    # The default Django finders:
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

This finder is important—it’s how Django finds the built versions of your files when you run collectstatic.

Development

In order to ease development, this package includes a middleware class that will automatically build your static files as part of the request-response cycle. In order to use it, just add it to your MIDDLEWARE_CLASSES setting:

MIDDLEWARE_CLASSES = (
    ...
    'staticbuilder.middleware.BuildOnRequest',
)

Now, whenever you access a view that returns an HTML response, staticbuilder will check to see if your static files have changed since the last build. If they have, it will trigger a new build. This way, your static files will always be up-to-date.

In order to make sure your responses are delivered quickly when developing, you’ll probably want to have different STATICBUILDER_BUILD_COMMANDS when DEBUG is True. (For example, you probably don’t need to compress your CSS and JS while developing.)

This middleware is automatically disabled when DEBUG is False, so it won’t run in production.

Collecting Without Building

The buildstatic command is actually a two-step process: collecting static files into a build directory, and running some shell commands. The first step is actually another command: collectforbuild. This command may be run by itself in the event that you want to do a different set of build steps than what you have configured (during a deployment, for example).

The buildstatic command accepts an optional --nocollect flag that will skip the collectforbuild step altogether. Note that this means collectforbuild will need to have been run at some point prior to buildstatic --nocollect.

Release History

Release History

0.6.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.5.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-staticbuilder-0.6.1.tar.gz (15.8 kB) Copy SHA256 Checksum SHA256 Source Feb 10, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting