title: Django static files versions
body: <p>How do you control  version of your static files in Django? I <a href="https://bitbucket.org/ad3w/django-sstatic/overview" rel="nofollow">wrote custom templatetag</a> which adds the modification date as GET parameter of file URL, but would like to know - whether I'm doing.</p>
  
  <p>Tag code:</p>
  
  <pre><code>import os
  
  from django import template
  from django.conf import settings
  
  
  register = template.Library()
  
  @register.simple_tag
  def sstatic(path):
      '''
      Returns absolute URL to static file with versioning.
      '''
      full_path = os.path.join(settings.STATIC_ROOT, path)
      try:
          # Get file modification time.
          mtime = os.path.getmtime(full_path)
          return '%s%s?%s' % (settings.STATIC_URL, path, mtime)
      except OSError:
          # Returns normal url if this file was not found in filesystem.
          return '%s%s' % (settings.STATIC_URL, path)
  </code></pre>