Django Admin 通过 apache 破坏了 CSS 链接,但可以在 runserver 模式下工作
由于某种原因,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我明白了。
对于生产服务器,您必须设置指向您提供的设置的链接。对我来说,我在 settings.py 文件中选择了 admin_media 文件夹:
为了告诉 apache 查找文件,您必须通过添加以下行来编辑启用站点的文件:
但请注意,这是指向django contrib admin 安装在我的服务器上。您的服务器可能有不同的安装,因此请查找您的设置。通过在终端中复制粘贴以下内容来找出您的 python 安装位置:
祝大家好运!
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:
And in order to tell apache to look for files, you have to edit your sites-enabled file by adding the line:
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:
Good luck to everybody!