Login

Tag "staticfiles"

Snippet List

Coffeescript compilation

All I wanted was for one to one compilation of coffeescript to javascript. * Without special templatetags * Without specifying explicit bundles * Served dynamically in development * Compiled by collectstatic for producton This code is the minimum required for this. There are two things to take into account: * list method to find coffeescript files to compile for collectstatic * find method to find coffeescript equivalent for a js file for django.contrib.staticfiles.views.serve. The list method will use the list method on all finders that come before it in STATICFILES_FINDERS to find all the files that end with .coffee and will return the equivalent .js path with a storage class that knows how to compile the coffeescript. The find method will use the find method on all finders that come before it in STATICFILES_FINDERS to locate the coffeescript file that is actually being requested. It will then compile the coffeescript into a file in settings.CACHE_DIR before serving that file.

  • development
  • staticfiles
  • coffeescript
  • collectstatic
Read More

Serve from STATIC_ROOT

Assuming you have defined STATIC_ROOT correctly in settings.py, and have installed staticfiles_urlpatterns() in urls.py (as demoed in the code, taken from Django's staticfiles docs), the code from static_root_finder.py can be used to simply serve static files in development from STATIC_ROOT directly, avoiding complicated setups in case we just want to have a bunch of static files in one directory.

  • staticfiles
  • STATIC_ROOT
Read More

collectstatic for media folders

Note: This concerns django 1.3 but the tags does not yet exist. We have a couple of apps, including 3rd party apps, that have the 'static' files in 'media' dirs. These files aren't found with collectstatic in django 1.3. With this snippet they will be. To use it: * paste the code in a file e.g. yourproject/finders.py. * include the finder in settings.STATICFILES_FINDERS: STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'yourproject.finders.AppMediaDirectoriesFinder', ) * ./manage.py collectstatic -n -l

  • media
  • staticfiles
Read More

3 snippets posted so far.