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 'correc开发者_如何学Pythont' (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?
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.
You need to add an alias for your static files to be served from. Something like:
Alias /myproject/static/ /var/www/djangoapps/myproject/media/static
This way Apache will serve the static files instead of asking django to handle it.
精彩评论