zoukankan      html  css  js  c++  java
  • Django admin 界面无法加载 CSS 问题解决方案(服务器 Apache 服务器)

    主要原因:

      未找到存放静态文件的目录

      没有访问目录的权限

    基础知识:

      在 CentOS 下面,Django 的静态文件存放在目录:

    /usr/lib/python2.7/site-packages/django/contrib/admin/static

      Django 的配置文件中:

    STATIC_URL = '/static/'

      当输入 URL: mysite/admin 时,服务器会去 mysite/static/admin/ 加载静态文件

      例如:

      所以,解决问题的思路是:确保 Apache 能够访问静态文件目录,并且有权限加载静态文件目录

    配置 Apache ,使之能访问存放静态文件的目录:

      打开 Apache 配置文件

    vim /etc/httpd/conf/httpd.conf
    

      添加如下信息

    #将 URL 中访问 /static 的请求,导向 /usr/lib/python2.7/site-packages/django/contrib/admin/static
    Alias /static /usr/lib/python2.7/site-packages/django/contrib/admin/static
    
    #Apache 允许访问静态文件目录
    <Directory /usr/lib/python2.7/site-packages/django/contrib/admin/static>
    Require all granted
    </Directory>

      同时注意 static 目录在 linux 下的权限,修改权限命令

      在 static 目录下

    sudo chmod 777 admin

       重启 Apache

    sudo systemctl restart httpd

      如果 Apache 重启不了,查看报错信息

    sudo systemctl status httpd

     

  • 相关阅读:
    P1182 数列分段`Section II` 二分
    洛谷 P1025 数的划分
    深浅拷贝
    数据的内置方法
    控制流程-if/while/for
    python的基本运算符
    花式赋值
    python的注释
    Python的垃圾回收机制
    变量与常量
  • 原文地址:https://www.cnblogs.com/ontheway703/p/5292431.html
Copyright © 2011-2022 走看看