I am currently serving my static files in Django. How do I use Apache2 to do this?
(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
As you can see, I have a directory called "media" under my Django project.
I would like to delete this line in my urls.py
and instead us Apache to serve my 开发者_运维知识库static files. What do I do to my Apache configs (which files do I change) in order to do this?
By the way, I installed Apache2 like normal:
sudo aptitude install apache2
I would read Django's official static files docs and apache mod_python documentation.
This example sets up Django at the site root but explicitly disables Django for the media subdirectory and any URL that ends with .jpg, .gif or .png:
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
</Location>
<Location "/media">
SetHandler None
</Location>
<LocationMatch "\.(jpg|gif|png)$">
SetHandler None
</LocationMatch>
精彩评论