Django,apachewsgi服务器正在提供/js和/css服务,但不能提供图像

2024-10-08 18:28:07 发布

您现在位置:Python中文网/ 问答频道 /正文

静态目录结构:

website
--css
--js
--images
  --landinpage.png

Apache访问日志: 在

^{pr2}$

HTML代码:

<code>

    <!-- Styles -->
    <link rel="stylesheet" type="text/css" href="/static/website/css/style.css"/>

<style>
body {
    background: white url("/static/website/images/landinpage.png");
</code>

我可以看到/static/website/css/样式.css正确加载(因此apache日志中有200个服务器响应),但当服务器尝试加载/static/website/images时/登陆页面.png我收到404的回复。 我已经核实了文件名和位置


Tags: 服务器目录pngstyleapachejs静态code
1条回答
网友
1楼 · 发布于 2024-10-08 18:28:07

如果是静态服务器apache2:

设置.py添加静态目录

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

收集静态目录

^{pr2}$

在apache conf中添加路径

Alias /static/ /var/www/static/

如果开发服务器。

模板上下文处理器设置.py

'django.template.context_processors.static',

网址.py

from django.conf import settings
from django.conf.urls.static import static

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

相关问题 更多 >

    热门问题