Sunday, January 20, 2013

The easy way to serve static content in Django with apache2

Struggling with how to serve static content (e.g., images referenced from your site template files, like logos) on both the django development server and apache2, without changing code?

A simple approach that does not involve changs to your django project is to add the following to /etc/apache2/apache2.conf:

Alias /static/ /foo/bar/djangoproject/djangoapplication/static/

This would correspond to the following settings in (located in /foo/bar/djangoproject):

STATIC_URL = '/static/'

Doing this allows you to run on the dev server (e.g., python runserver) and when deployed on an apache2 host without any changes to the project.

No comments:

Post a Comment