简体   繁体   English

我目前正在Django中提供我的静态文件。 我如何使用Apache2来做到这一点?

[英]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. 如您所见,我的Django项目下有一个名为“media”的目录。

I would like to delete this line in my urls.py and instead us Apache to serve my static files. 我想删除我的urls.py这一行,而不是我们的Apache来提供我的静态文件。 What do I do to my Apache configs (which files do I change) in order to do this? 为了做到这一点,我该如何对我的Apache配置(我要更改哪些文件)?

By the way, I installed Apache2 like normal: 顺便说一下,我像正常一样安装了Apache2:

sudo aptitude install apache2

I would read Django's official static files docs and apache mod_python documentation . 我会阅读Django的官方静态文件docsapache mod_python文档

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: 此示例在站点根目录设置Django,但显式禁用了媒体子目录的Django以及以.jpg,.gif或.png结尾的任何URL:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM