Django Admin 通过 apache 破坏了 CSS 链接,但可以在 runserver 模式下工作

发布于 2024-10-06 15:31:26 字数 665 浏览 0 评论 0原文

由于某种原因,django 管理在某个时候被破坏了。 CSS 丢失了。

以下是我的设置:

MEDIA_ROOT = os.path.normpath(os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

但是,管理页面上生成的行仍然是:

<link rel="stylesheet" type="text/css" href="/admin_media/css/base.css" />

但该网站在此文件上给了我 404 。

而且它变得更好 - 如果我使用 apache 查看项目,就会出现这个问题。如果我使用 python manage.py runserver ,那么管理员工作得很好。

有任何线索说明为什么会发生这种情况吗? - 重新启动apache,这没有帮助。

这是我在 urls 文件中的内容:

    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

For some reason, at some point the django administration got broken. The css is missing.

Here are my settings:

MEDIA_ROOT = os.path.normpath(os.path.join(SITE_ROOT, 'media/'))
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'

However, the generated line on the admin page is still:

<link rel="stylesheet" type="text/css" href="/admin_media/css/base.css" />

but the site gives me 404 on this file.

And it gets better - if I use apache to view the project, that problem occurs. If I use python manage.py runserver the admin works well.

Any clues to why that might be happening?
- restarted apache, that didn't help.

here is what i have in the urls file:

    (r'^media/(?P<path>.*)
, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2024-10-13 15:31:26

好吧,我明白了。

对于生产服务器,您必须设置指向您提供的设置的链接。对我来说,我在 settings.py 文件中选择了 admin_media 文件夹:

ADMIN_MEDIA_PREFIX = '/admin_media/'

为了告诉 apache 查找文件,您必须通过添加以下行来编辑启用站点的文件:

Alias /admin_media/ /usr/lib/python2.6/dist-packages/django/contrib/admin/media/

但请注意,这是指向django contrib admin 安装在我的服务器上。您的服务器可能有不同的安装,因此请查找您的设置。通过在终端中复制粘贴以下内容来找出您的 python 安装位置:

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

祝大家好运!

Ok, I figured it out.

For production server, you have to setup a link to the setting you provided. For me, i chose admin_media folder, in the settings.py file:

ADMIN_MEDIA_PREFIX = '/admin_media/'

And in order to tell apache to look for files, you have to edit your sites-enabled file by adding the line:

Alias /admin_media/ /usr/lib/python2.6/dist-packages/django/contrib/admin/media/

Note though, that this is the path to the django contrib admin as installed on my server. Your server might have a different installation, so look up your settings. find out where your python is installed by copy pasting this in terminal:

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

Good luck to everybody!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文