dj-static-0.0.6/0000755000076500000240000000000012360015600014023 5ustar kreitzstaff00000000000000dj-static-0.0.6/dj_static.egg-info/0000755000076500000240000000000012360015600017461 5ustar kreitzstaff00000000000000dj-static-0.0.6/dj_static.egg-info/dependency_links.txt0000644000076500000240000000000112360015600023527 0ustar kreitzstaff00000000000000 dj-static-0.0.6/dj_static.egg-info/not-zip-safe0000644000076500000240000000000112360015571021716 0ustar kreitzstaff00000000000000 dj-static-0.0.6/dj_static.egg-info/PKG-INFO0000644000076500000240000000332012360015600020554 0ustar kreitzstaff00000000000000Metadata-Version: 1.1 Name: dj-static Version: 0.0.6 Summary: Serve production static files with Django. Home-page: https://github.com/kennethreitz/dj-static Author: Kenneth Reitz Author-email: me@kennethreitz.com License: BSD Description: dj-static ~~~~~~~~~ This is a simple Django middleware utility that allows you to properly serve static assets from production with a WSGI server like Gunicorn. Django `doesn't recommend `_ the production use of its static file server for a number of reasons. There exists, however, a lovely WSGI application aptly named `Static `_. It is suitable for the production use of static file serving, unlike Django. Usage ----- Configure your static assets in ``settings.py``:: STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' Then, update your ``wsgi.py`` file to use dj-static:: from django.core.wsgi import get_wsgi_application from dj_static import Cling application = Cling(get_wsgi_application()) Platform: any Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content Classifier: Topic :: Software Development :: Libraries :: Python Modules dj-static-0.0.6/dj_static.egg-info/requires.txt0000644000076500000240000000000712360015600022056 0ustar kreitzstaff00000000000000static3dj-static-0.0.6/dj_static.egg-info/SOURCES.txt0000644000076500000240000000034412360015600021346 0ustar kreitzstaff00000000000000README.rst dj_static.py setup.py dj_static.egg-info/PKG-INFO dj_static.egg-info/SOURCES.txt dj_static.egg-info/dependency_links.txt dj_static.egg-info/not-zip-safe dj_static.egg-info/requires.txt dj_static.egg-info/top_level.txtdj-static-0.0.6/dj_static.egg-info/top_level.txt0000644000076500000240000000001212360015600022204 0ustar kreitzstaff00000000000000dj_static dj-static-0.0.6/dj_static.py0000644000076500000240000000726512360015456016364 0ustar kreitzstaff00000000000000# -*- coding: utf-8 -*- import static from django.conf import settings from django.core.handlers.wsgi import WSGIHandler from django.contrib.staticfiles.handlers import StaticFilesHandler as DebugHandler try: from urllib.parse import urlparse except ImportError: # Python 2 from urlparse import urlparse from django.contrib.staticfiles import utils try: from django.core.handlers.wsgi import get_path_info except ImportError: # django < 1.7 try: from django.core.handlers.base import get_path_info except ImportError: # django < 1.5 import sys py3 = sys.version_info[0] == 3 def get_path_info(environ): """ Returns the HTTP request's PATH_INFO as a unicode string. """ path_info = environ.get('PATH_INFO', str('/')) # Under Python 3, strings in environ are decoded with ISO-8859-1; # re-encode to recover the original bytestring provided by the web server. if py3: path_info = path_info.encode('iso-8859-1') # It'd be better to implement URI-to-IRI decoding, see #19508. return path_info.decode('utf-8') class Cling(WSGIHandler): """WSGI middleware that intercepts calls to the static files directory, as defined by the STATIC_URL setting, and serves those files. """ def __init__(self, application, base_dir=None, ignore_debug=False): self.application = application self.ignore_debug = ignore_debug if not base_dir: base_dir = self.get_base_dir() self.base_url = urlparse(self.get_base_url()) self.cling = static.Cling(base_dir) try: self.debug_cling = DebugHandler(application, base_dir=base_dir) except TypeError: self.debug_cling = DebugHandler(application) super(Cling, self).__init__() def get_base_dir(self): return settings.STATIC_ROOT def get_base_url(self): utils.check_settings() return settings.STATIC_URL @property def debug(self): return settings.DEBUG def _transpose_environ(self, environ): """Translates a given environ to static.Cling's expectations.""" environ['PATH_INFO'] = environ['PATH_INFO'][len(self.base_url[2]) - 1:] return environ def _should_handle(self, path): """Checks if the path should be handled. Ignores the path if: * the host is provided as part of the base_url * the request's path isn't under the media path (or equal) """ return path.startswith(self.base_url[2]) and not self.base_url[1] def __call__(self, environ, start_response): # Hand non-static requests to Django if not self._should_handle(get_path_info(environ)): return self.application(environ, start_response) # Serve static requests from static.Cling if not self.debug or self.ignore_debug: environ = self._transpose_environ(environ) return self.cling(environ, start_response) # Serve static requests in debug mode from StaticFilesHandler else: return self.debug_cling(environ, start_response) class MediaCling(Cling): def __init__(self, application, base_dir=None): super(MediaCling, self).__init__(application, base_dir=base_dir) # override callable attribute with method self.debug_cling = self._debug_cling def _debug_cling(self, environ, start_response): environ = self._transpose_environ(environ) return self.cling(environ, start_response) def get_base_dir(self): return settings.MEDIA_ROOT def get_base_url(self): return settings.MEDIA_URL dj-static-0.0.6/PKG-INFO0000644000076500000240000000332012360015600015116 0ustar kreitzstaff00000000000000Metadata-Version: 1.1 Name: dj-static Version: 0.0.6 Summary: Serve production static files with Django. Home-page: https://github.com/kennethreitz/dj-static Author: Kenneth Reitz Author-email: me@kennethreitz.com License: BSD Description: dj-static ~~~~~~~~~ This is a simple Django middleware utility that allows you to properly serve static assets from production with a WSGI server like Gunicorn. Django `doesn't recommend `_ the production use of its static file server for a number of reasons. There exists, however, a lovely WSGI application aptly named `Static `_. It is suitable for the production use of static file serving, unlike Django. Usage ----- Configure your static assets in ``settings.py``:: STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' Then, update your ``wsgi.py`` file to use dj-static:: from django.core.wsgi import get_wsgi_application from dj_static import Cling application = Cling(get_wsgi_application()) Platform: any Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content Classifier: Topic :: Software Development :: Libraries :: Python Modules dj-static-0.0.6/README.rst0000644000076500000240000000357612360015456015536 0ustar kreitzstaff00000000000000DJ-Static ========= This is a simple Django middleware utility that allows you to properly serve static assets from production with a WSGI server like Gunicorn. Django `doesn't recommend `_ the production use of its static file server for a number of reasons. There exists, however, a lovely WSGI application aptly named `Static `_. .. image:: http://farm8.staticflickr.com/7387/8907351990_58677d7c35_z.jpg "Finally, a super-simple way of serving assets in Django that’ll actually perform well" — `@jacobian `_ It is suitable for the production use of static file serving, unlike Django. Enjoy! Shouldn't I use a CDN? ---------------------- If you have to ask that question, there's actually quite a good chance you don't. Static responses aren't very different than dynamic ones. If you're running a top-tier application, optimizing for delivery and reducing frontend load, you will want to explore using a CDN with `Django-Storages `_. Usage ----- :: $ pip install dj-static Configure your static assets in ``settings.py``:: STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' Then, update your ``wsgi.py`` file to use dj-static:: from django.core.wsgi import get_wsgi_application from dj_static import Cling application = Cling(get_wsgi_application()) File uploads (optional) ^^^^^^^^^^^^^^^^^^^^^^^ In case you also want to serve media files that were uploaded to ``MEDIA_ROOT``:: MEDIA_ROOT = 'media' MEDIA_URL = '/media/' Then again, update your ``wsgi.py`` file:: from django.core.wsgi import get_wsgi_application from dj_static import Cling, MediaCling application = Cling(MediaCling(get_wsgi_application())) dj-static-0.0.6/setup.cfg0000644000076500000240000000007312360015600015644 0ustar kreitzstaff00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 dj-static-0.0.6/setup.py0000644000076500000240000000334212360015456015550 0ustar kreitzstaff00000000000000# -*- coding: utf-8 -*- """ dj-static ~~~~~~~~~ This is a simple Django middleware utility that allows you to properly serve static assets from production with a WSGI server like Gunicorn. Django `doesn't recommend `_ the production use of its static file server for a number of reasons. There exists, however, a lovely WSGI application aptly named `Static `_. It is suitable for the production use of static file serving, unlike Django. Usage ----- Configure your static assets in ``settings.py``:: STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' Then, update your ``wsgi.py`` file to use dj-static:: from django.core.wsgi import get_wsgi_application from dj_static import Cling application = Cling(get_wsgi_application()) """ from setuptools import setup setup( name='dj-static', version='0.0.6', url='https://github.com/kennethreitz/dj-static', license='BSD', author='Kenneth Reitz', author_email='me@kennethreitz.com', description='Serve production static files with Django.', long_description=__doc__, py_modules=['dj_static'], zip_safe=False, install_requires=['static3'], include_package_data=True, platforms='any', classifiers=[ 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development :: Libraries :: Python Modules' ] )