Django 管理页面缺少 CSS
我看到了这个 问题和来自 Django 项目的建议 在这里,但仍然无法使其正常工作.我的 Django 管理页面根本不显示 CSS.
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.
这是我目前的配置.
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>
此外,我还运行以下命令来创建(我认为)符号链接ln -s/home/djangotest/sgel/media/admin//usr/lib/python2.6/site-packages/django/contrib/admin/media/
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/
更新
在我的 httpd.conf 文件中,
In my httpd.conf file,
User django
Group django
当我在 /media
目录中运行 ls -l 时
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
root 用户应该是 django 吗?
Should that root user be django instead?
更新 2当我在 /media/admin
文件夹中输入 ls -la
时
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/
问题是,当我导航到 /usr/lib/python2.6/site-packages/django/contrib/admin/media/
时,该文件夹是空的.因此,我将 Django 安装中的 CSS、IMG 和 JS 文件夹复制到 /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
推荐答案
除了按照 Daniel Roseman 的建议更正符号链接之外,您还需要确保运行 Apache 的用户对管理媒体具有读取权限.
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.
- 如果你在你的媒体目录中执行
ls -l
,你看到符号链接了吗? - 如果您从您的媒体目录中
cd admin
,它会起作用吗?如果你然后运行 ls
你能看到管理媒体吗? - 运行 Apache 的用户是否具有对管理媒体的读取权限?
- 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 runls
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.
/usr/lib/python2.6/site-packages/django/contrib/admin/media/
为空的事实也令人不安.解决眼前的问题后,您可能需要考虑在预期的位置重新安装 django.
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
也就是说,在 media/
目录中,它们应该是一个名为 admin
的链接,直接指向您的 /admin/media
目录django 安装.
That is, inside of the media/
directory their should be a link called admin
directly to the /admin/media
directory of your django installation.
要修复你所拥有的,在 media/admin/
目录中运行:
To fix what you've got, inside of the media/admin/
directory run:
rm media
cd ..
rmdir admin
然后按照 Daniel Roseman 的回答中的建议重新创建符号链接.
and then re-create the symlink as suggested in Daniel Roseman's answer.
相关文章