[英]Django static files 404 on server, although working locally
I have deployed a django application on an apache server using WSGI but the static files give me 404 errors although everything worked fine on my PC using Django's development server. 我已经在使用WSGI的apache服务器上部署了django应用程序,但是尽管使用Django的开发服务器在PC上一切正常,但静态文件却给我404错误。
My apache2.conf: 我的apache2.conf:
WSGIScriptAlias /app /srv/App/App/wsgi.py
WSGIPythonPath /srv/App
<Directory /srv/App/App>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
settings.py settings.py
STATIC_URL = '/app/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
sample of how I call static files through my templates 我如何通过模板调用静态文件的示例
{% load staticfiles %}
...
<link rel="stylesheet" href='{% static "css/main.css" %}'>
The only thing different than my local version of the app is that my STATIC_URL on settings.py doesn't include the '/app' part. 与我的本地应用程序版本唯一不同的是,我settings.py上的STATIC_URL不包含“ / app”部分。 According to Chrome's Developer Tools the URL of my static files is:
根据Chrome的开发人员工具,我的静态文件的网址为:
http://.../app/static/css/main.css
(using the static file of my template example) which I think should be right and can not understand the reason it's not working. (使用模板示例的静态文件),我认为这是正确的,并且无法理解其无法正常工作的原因。
This is an issue that comes too often. 这是一个经常出现的问题。 You have to:
你必须:
STATIC_ROOT
STATIC_ROOT
collectstatic
collectstatic
STATICFILES_DIRS
is not needed for live (handled by Apache). STATICFILES_DIRS
状态不需要STATICFILES_DIRS
(由Apache处理)。 Take a look at Django documentation: Managing static files 看一下Django文档:管理静态文件
You don't have any Alias
directives in Apache configuration telling Apache where your static files are and what URL you want them to appear under. Apache配置中没有任何
Alias
指令可告诉Apache静态文件在哪里以及您希望它们在哪个URL下显示。 See: 看到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.