吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 670|回复: 3
收起左侧

[已解决] Apache2 mod_wsgi 部署Django项目,静态文件设置?

[复制链接]
Cool_Breeze 发表于 2021-12-30 20:15
本帖最后由 Cool_Breeze 于 2021-12-31 08:42 编辑

Apache2 错误log如下:
  • [Thu Dec 30 20:04:57.860038 2021] [core:info] [pid 179029:tid 140030832015104] [client 113.119.10.20:6409] AH00128: File does not exist: /root/app/mysite/images/\xe9\x9b\x8f\xe7\x94\xb0.jpg, referer: http://106.12.132.135/

项目静态文件再static文件夹下面:
  • root@localhost:~/app/mysite# ll
  • total 168
  • drwxrwxrwx 6 root root   4096 Dec 30 20:04 ./
  • drwxr-xr-x 5 root root   4096 Dec 29 08:57 ../
  • -rwxrwxrwx 1 root root 143360 Dec 30 20:04 db.sqlite3*
  • drwxr-xr-x 6 root root   4096 Dec 30 19:25 ipinfo/
  • -rwxr-xr-x 1 root root    662 Dec 28 08:34 manage.py*
  • drwxr-xr-x 3 root root   4096 Dec 30 20:09 mysite/
  • drwxr-xr-x 6 root root   4096 Dec 30 19:49 static/

django项目setting.py
  • STATIC_URL = '/static/'
  • STATIC_ROOT = BASE_DIR / 'static'

Apache老是去 /root/app/mysite/images/ 目录下面去,没有设置对。。。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| Cool_Breeze 发表于 2021-12-30 20:37
没办法了只能在模板里面加了static了!

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>ipinfo</title>
        {% load static %}
        <link rel="stylesheet" type="text/css" href="{% static '/static/css/style.css' %}"
    </head>
    <body>
        <table border="1">
            <tr>
                <th>服务器日期时间</th>
                <th>当前IP地址</th>
                <th>访问当前页面次数</th>
                <th>最后一次访问当前页面时间</th>
            </tr>
            <tr>
                <th>{{ current }}</th>
                <th>{{ accessip.ip }}</th>
                <th>{{ accessip.count }}</th>
                <th>{{ accessip.last_date }}</th>
            </tr>
        </table>
                <img src="{% static 'static/images/雏田.jpg'%}"
    </body>
</html>
 楼主| Cool_Breeze 发表于 2021-12-31 08:41
已经搞定了, Apache2 配置文件里的 alias static 重名了。
 楼主| Cool_Breeze 发表于 2021-12-31 08:52
[HTML] 纯文本查看 复制代码
Alias /media/ /root/app/mysite/media/
Alias /static/ /root/app/mysite/static/
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /root/app/mysite/mysite/wsgi.py
WSGIPythonHome /usr/
WSGIPythonPath /root/app/mysite/
<Directory /root/app/mysite/>
<IfVersion < 2.4>
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.4>
    Require all granted
</IfVersion>
</Directory>


<Directory /root/app/mysite/media/>
<IfVersion < 2.4>
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.4>
    Require all granted
</IfVersion>
</Directory>

<Directory /root/app/mysite/static/>
<IfVersion < 2.4>
    Order allow,deny
    Allow from all
</IfVersion>
<IfVersion >= 2.4>
    Require all granted
</IfVersion>
</Directory>
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-17 20:08

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表