Coder Social home page Coder Social logo

jlachowski / dj-static Goto Github PK

View Code? Open in Web Editor NEW

This project forked from heroku-python/dj-static

0.0 1.0 0.0 163 KB

Serve production static files with Django.

Home Page: http://kennethreitz.org/introducing-dj-static/

License: BSD 2-Clause "Simplified" License

Python 100.00%

dj-static's Introduction

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.

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's People

Contributors

agriffis avatar andrewsg avatar axelmagn avatar gciding avatar goldibex avatar gone avatar jezdez avatar jlachowski avatar kennethreitz avatar maria avatar metakermit avatar stefanw avatar tinnet avatar treyhunner avatar wking avatar wnh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.