Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install django-simplestatic

How to install django-simplestatic

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-simplestatic
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
0.0.5 Available View build log
 
License
MIT
Dependencies
Lastest release
version 0.0.5 on May 23rd, 2013

Django SimpleStatic is an opinionated Django app which makes it very simple to deal with static media, with extremely minimal configuration, as long as:

  • You store your static media in one directory, rather than alongside each app.
  • You want your files served from S3, rather from your own servers.
  • You want to use Google Closure Compiler to compress your JavaScript.
  • You want to compress your javascript ahead of time, rather than during the request.
  • You don't use any of those fancy CSS precompilers like LESS or SCSS. (This may change someday as my personal preferences change.)

If any of the above don't hold true, then this library probably won't work for you. That said, if all of the above do hold true for you, then this app will likely be the simplest and best way to handle your static media.

Installation

  1. pip install django-simplestatic
  2. Add 'simplestatic' to your INSTALLED_APPS:

System Message: ERROR/3 (<string>, line 27)

Unknown directive type "code-block".

.. code-block:: python

    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.admin',

        # ... all your installed apps

        'simplestatic',
    )

  1. In your settings file, set the following values:

System Message: ERROR/3 (<string>, line 43)

Unknown directive type "code-block".

.. code-block:: python

    SIMPLESTATIC_DIR = '/path/to/your/static/media/directory'

    AWS_ACCESS_KEY_ID = 'YOUR_ACCESS_KEY_HERE'
    AWS_SECRET_ACCESS_KEY = 'YOUR_SECRET_KEY_HERE'
    AWS_STORAGE_BUCKET_NAME = 'YOUR_STATIC_BUCKET_HERE'

  1. In your urls.py, import the simplestatic_debug_urls function and execute it to the end of your urlpatterns:

System Message: ERROR/3 (<string>, line 54)

Unknown directive type "code-block".

.. code-block:: python

    from simplestatic.urls import simplestatic_debug_urls

    urlpatterns = patterns('',
        # ... all of your url patterns right here
    ) + simplestatic_debug_urls()

  1. In your template (or templates) import and use the simplestatic template tags, which might look something like this:

System Message: ERROR/3 (<string>, line 65)

Unknown directive type "code-block".

.. code-block:: html+django

    {% load simplestatic_tags %}

    <head>
      <title>I love django-simplestatic!</title>

      {% simplestatic %}
        {% compress_css "css/bootstrap.css" %}
        {% compress_css "css/screen.css" %}
        {% compress_js "js/jquery-1.9.1.js" %}
        {% compress_js "js/global.js" %}
      {% endsimplestatic %}
    </head>

  1. Before you push your code, run the static_sync management command to compress any CSS and JS and upload the whole directory to S3:

System Message: ERROR/3 (<string>, line 83)

Unknown directive type "code-block".

.. code-block:: console

    python manage.py static_sync


Advanced Configuration

Even though in the vast majority of cases, you'll only need to do what was mentioned above, django-simplestatic offers a number of settings that you might want to tweak. Provided here is a reference of every setting

Required Settings
SIMPLESTATIC_DIR:
The directory where you store all of your static media.
AWS_ACCESS_KEY_ID:
Your Amazon Web Services access key.
AWS_SECRET_ACCESS_KEY:
Your Amazon Web Services secret access key.
AWS_STORAGE_BUCKET_NAME:
The S3 bucket in which to store and serve all of your static media.
Optional Settings
SIMPLESTATIC_DEBUG: (Defaults to DEBUG)
A boolean determining whether to use the minimized, compressed versions of the files uploaded to S3. If set to True, then the full development versions of the files will be served instead. You shouldn't have to touch this, as by default it's set to the same value as your Django DEBUG value.
SIMPLESTATIC_DEBUG_PATH: (Defaults to 'static/')
The URL path from which to serve static media during development.
SIMPLESTATIC_CUSTOM_DOMAIN: (Defaults to S3 subdomain URL)

A custom domain from which to serve static media in production. For example, you may want to use CloudFront as a CDN in front of your S3 bucket, which can be achieved by

System Message: ERROR/3 (<string>, line 129)

Unknown directive type "code-block".

.. code-block:: python

    SIMPLESTATIC_CUSTOM_DOMAIN = 'asdfasdf.cloudfront.net'


SIMPLESTATIC_COMPRESSED_DIR: (Defaults to 'compressed')

The URL path in S3 to place the compressed and minified versions of the CSS and JS.

For example, in the default case where this is set to 'compressed', your css and js might be located in a location like one of the following:

http://example.s3.amazonaws.com/compressed/6bf0c67b74b26425832a17bbf27b9cb9.css http://example.s3.amazonaws.com/compressed/97a548fc6b62d5bb9f50e6a95b25d8db.js
CLOSURE_COMPILATION_LEVEL: (Defaults to 'SIMPLE_OPTIMIZATIONS')

The Google Closure Compiler compilation level option. See the following page for more information:

https://developers.google.com/closure/compiler/docs/compilation_levels
CLOSURE_COMPILER_COMMAND: (Defaults to 'java -jar /path/to/supplied/closure.jar')
The command required to run Google Closure Compiler.

Subscribe to package updates

Last updated May 23rd, 2013

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.