Serving static files while running Django&mod_wsgi on Apache 2.2

陌路散爱 提交于 2019-12-24 23:45:22

问题


I have changed my Apache 2.2's httpd.conf

#Serve static files
Alias /static/ "E:\Python\Django\carlsblog\static\"
<Directory "E:\Python\Django\carlsblog\static">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>

#Start mod_wsgi as default handler
WSGIScriptAlias / "E:\Python\Django\carlsblog\django.wsgi"

<Directory "E:\Python\Django\carlsblog">
Allow from all
</Directory>

and my app can be successfully run, only the static files cannot be accessed, a 404 is thrown by Django

However, if I change this line

Alias /static/ "E:\Python\Django\carlsblog\static\"

into

Alias /static/ "E:\Python\Django\carlsblog\static"

the index page of the static folder can be seen, but the files cannot be reached. When I checked Apache's error log at this time, I found something like this:

File does not exist "E:\Python\Django\carlsblog\staticmy_static_file.txt"

it seems there's a "\" missing, anyone has an idea on fixing this?


回答1:


Try removing the trailing slash from the alias itself:

Alias /static "E:\Python\Django\carlsblog\static"

Update (2015): This answer is from 2011. Currently, it is considered a much better practice to use gunicorn + nginx to serve django apps.




回答2:


Are your templates OK? Check your generated html using View Source in your browser.



来源:https://stackoverflow.com/questions/6402185/serving-static-files-while-running-djangomod-wsgi-on-apache-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!