Django管理员页面缺少CSS [英] Django Admin Page missing CSS

查看:140
本文介绍了Django管理员页面缺少CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个问题和来自Django项目的建议这里但仍然不能得到这个工作。我的Django管理员页面根本不显示CSS。





这是我当前的配置。



settings.py

  ADMIN_MEDIA_PREFIX ='/ media / admin /'

httpd.conf >

 < VirtualHost *:80> 
DocumentRoot / home / django / sgel
ServerName ec2 - *** - ** - *** - ***。ap - ********** - 1.compute。 amazonaws.com
ErrorLog /home/django/sgel/logs/apache_error.log
CustomLog /home/django/sgel/logs/apache_access.log combined
WSGIScriptAlias / / home / django / sgel /apache/django.wsgi

< Directory / home / django / sgel / media>
订单deny,允许
允许所有
< / Directory>

< Directory / home / django / sgel / apache>
订单deny,允许
允许所有
< / Directory>

LogLevel warn

Alias / media / / home / django / sgel / media /

< / VirtualHost>

< VirtualHost *:80>
ServerName sgel.com
永久重定向/ http://www.sgel.com/
< / VirtualHost>

此外,我还运行以下代码创建(我认为)符号链接
ln -s / home / djangotest / sgel / media / admin / /usr/lib/python2.6/site-packages/django/contrib/admin/media/



UPDATE



在我的httpd.conf档案中,

 用户django 
组django


$ b b

当我在 / media 目录中运行ls -l时

  drwxr-xr-x 2 root root 4096 Apr 4 11:03 admin 
-rw-r - r-- 1 root root 9 Apr 8 09:02 test.txt



这个root用户应该是django吗?



UPDATE 2
当我在 / media / admin 文件夹中输入 ls -la

 共12 
drwxr-xr-x 2根root 4096 Apr 13 03:33。
drwxr-xr-x 3 root root 4096 Apr 8 09:02 ..
lrwxrwxrwx 1 root root 60 Apr 13 03:33 media - > /usr/lib/python2.6/site-packages/django/contrib/admin/media/

事情是,当我导航到 /usr/lib/python2.6/site-packages/django/contrib/admin/media/ 时,该文件夹为空。所以我将我的Django安装中的CSS,IMG和JS文件夹复制到 /usr/lib/python2.6/site-packages/django/contrib/admin/media / 中;它仍然不工作

解决方案

除了纠正像Daniel Roseman建议的符号链接,你需要确保




  • 如果您执行 ls -l 在您的媒体目录中,您看到符号链接吗?

  • 如果您 cd admin ,它工作吗?如果您随后运行 ls ,您是否可以看到管理媒体?

  • 运行Apache的用户是否具有对管理媒体的读取权限?



如果所有这些操作都正常,请使用当前配置和这些命令的结果更新您的问题,



回复更新:好的,权限看起来不错。看起来你的媒体目录中的目录结构有点错误。



事实上, / usr / lib / python2。 6 / site-packages / django / contrib / admin / media / 是空的也是令人不安的。一旦你解决了直接的问题,你可能想在预期的地方重新安装django。



无论如何,结构应该如何:

  $ cd media 
$ ls -la
drwxr-xr-x 2 root root 4096 Apr 13 03:33。
drwxr-xr-x 3 root root 4096 Apr 8 09:02 ..
lrwxrwxrwx 1 root root 60 Apr 13 03:33 admin - > /usr/lib/python2.6/site-packages/django/contrib/admin/media/
-rw-r - r-- 1 root root 9 Apr 8 09:02 test.txt



也就是说,在 media / 一个直接连接到您的django安装的 / admin / media 目录的 admin 链接。



要修复您在 media / admin / 目录中运行的内容:

  rm media 
cd ..
rmdir admin

,然后按照Daniel Roseman的回答中的建议重新创建符号链接。


I saw this question and recommendation from Django Projects here but still can't get this to work. My Django Admin pages are not displaying the CSS at all.

This is my current configuration.

settings.py

ADMIN_MEDIA_PREFIX = '/media/admin/'

httpd.conf

<VirtualHost *:80>
    DocumentRoot /home/django/sgel
    ServerName ec2-***-**-***-***.ap-**********-1.compute.amazonaws.com
    ErrorLog /home/django/sgel/logs/apache_error.log
    CustomLog /home/django/sgel/logs/apache_access.log combined
    WSGIScriptAlias / /home/django/sgel/apache/django.wsgi

    <Directory /home/django/sgel/media>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory /home/django/sgel/apache>
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    Alias /media/ /home/django/sgel/media/

</VirtualHost>

<VirtualHost *:80>
   ServerName sgel.com
   Redirect permanent / http://www.sgel.com/
</VirtualHost>

In addition, I also ran the following to create (I think) the symbolic link ln -s /home/djangotest/sgel/media/admin/ /usr/lib/python2.6/site-packages/django/contrib/admin/media/

UPDATE

In my httpd.conf file,

User django
Group django

When I run ls -l in my /media directory

drwxr-xr-x 2 root root 4096 Apr  4 11:03 admin
-rw-r--r-- 1 root root    9 Apr  8 09:02 test.txt

Should that root user be django instead?

UPDATE 2 When I enter ls -la in my /media/admin folder

total 12
drwxr-xr-x 2 root root 4096 Apr 13 03:33 .
drwxr-xr-x 3 root root 4096 Apr  8 09:02 ..
lrwxrwxrwx 1 root root   60 Apr 13 03:33 media -> /usr/lib/python2.6/site-packages/django/contrib/admin/media/

The thing is, when I navigate to /usr/lib/python2.6/site-packages/django/contrib/admin/media/, the folder was empty. So I copied the CSS, IMG and JS folders from my Django installation into /usr/lib/python2.6/site-packages/django/contrib/admin/media/ and it still didn't work

解决方案

In addition to correcting the symbolic link as Daniel Roseman suggested, you'll need to make sure that the user that is running Apache has read access to the admin media.

  • If you do ls -l in your media directory, do you see the symbolic link?
  • If you cd admin from your media directory, does it work? If you then run ls can you see the admin media?
  • Does the user that runs Apache have read access to the admin media?

If all those things work, then please update your question with your current configuration and results of those commands and we'll take another look.

Response to Update: Ok, the permissions look ok. It looks like you've got the directory structure in your media directory a little bit wrong.

The fact that /usr/lib/python2.6/site-packages/django/contrib/admin/media/ was empty is disturbing, too. Once you solve the immediate problem you may want to look into reinstall django in the expected place.

Anyways, here's how the structure should look:

$ cd media
$ ls -la
drwxr-xr-x 2 root root 4096 Apr 13 03:33 .
drwxr-xr-x 3 root root 4096 Apr  8 09:02 ..
lrwxrwxrwx 1 root root   60 Apr 13 03:33 admin -> /usr/lib/python2.6/site-packages/django/contrib/admin/media/
-rw-r--r-- 1 root root    9 Apr  8 09:02 test.txt

That is, inside of the media/ directory their should be a link called admin directly to the /admin/media directory of your django installation.

To fix what you've got, inside of the media/admin/ directory run:

rm media
cd ..
rmdir admin

and then re-create the symlink as suggested in Daniel Roseman's answer.

这篇关于Django管理员页面缺少CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆