djangoapacheconfigurationmod-python

Serving static files on a webserver in Django


I am setting up my site on an external server (AWS). Everything seems to be working except for the static files (CSS and images).

My project is set up like so --

/var/www/
     djangoapps
         myproject
             settings.py, apps, etc.    
     djangotemplates
         myproject
             HTML files
/var/www/html
     media
         static    
             Images & CSS files

In the httpd conf file I have --

<Location /mysite>
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE mysite.settings
        SetEnv PYTHON_EGG_CACHE "/var/cache/www/pythoneggs"
        PythonDebug Off
        PythonPath "['/var/www/djangoapps'] + sys.path"
</Location>

<Location "/media/">
       SetHandler None
</Location>

And in settings.py --

STATIC_URL = '/myproject/static/'
STATICFILES_DIRS = ('/var/www/html/media/static/',)

When I load the page, the templates are working, and the URL to the image files is 'correct' (e.g., background: url("/myproject/static/email.jpg"). However, the images are not loading. What do I need to change so that the images and CSS will load properly?


Solution

  • Have you seen the official docs on serving static media with mod_python? I suspect you need a similar SetHandler for your static files that you do for your media files.

    Also, mod_python is deprecated.