Django admin 没有样式
我刚刚将我的 django 站点移到我的临时服务器上,并且该站点的管理端没有样式,以前在本地开发时它很好,我在某处读到我需要创建一个符号链接,我通过以下方式做到了这样做
sudo ln -s /var/www/sico/htdocs /usr/lib/python2.5/site-packages/django/contrib/admin/
但没有做任何事情我还可以尝试其他什么吗?
I have just moved my django site on my staging server, and the admin side of the site has no styling with it, when previously in local development it was fine, I read somewhere that I need to create a symbolic link, I did that by doing this
sudo ln -s /var/www/sico/htdocs /usr/lib/python2.5/site-packages/django/contrib/admin/
but that has done nothing is there anything else that I can try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的 Web 服务器设置,您可以通过以下两种方式之一进行操作:
符号链接
在网站的根文件夹中,您应该创建一个指向 Django 管理媒体目录的符号链接,名称名称为
ADMIN_MEDIA_PREFIX
在 Django 应用程序的设置中。默认情况下,这是/media/
,因此在您的 Web 根文件夹中,创建一个名为media
到/usr/lib/python2.5/site-packages 的符号链接/django/contrib/admin/media
。 (请注意符号链接末尾的尾随media
,您自己的示例中缺少该符号链接 - Django 管理媒体位于media
子目录in< /代码>contrib/admin`)。
Apache 别名
如果您的生产服务器是 Apache,并且您可以更改根配置,则可以使用 mod_alias 来设置 Django 管理媒体的路径。再次,假设您的 ADMIN_MEDIA_PREFIX 为
/media/
,您可以像这样设置别名:这样,路径
/media/ 下的所有请求code> 将解析到该目录。
大多数其他服务器都存在类似的技术,例如 Lighttpd 或 nginx;如果您不使用 Apache,请查阅服务器的文档。
使用 Apache 的
mod_alias
的解决方案可能最适合部署,但符号链接方法也同样有效。您的应用程序在临时服务器上运行的原因很可能是因为它与 Django 的内部 Web 服务器一起运行,该服务器可以自动解析管理媒体目录的路径。
Depending on your web server setup, you can do it one of two ways:
Symlinking
In your website's root folder, you should create a symbolic link to your Django admin media directory, with the name name as the
ADMIN_MEDIA_PREFIX
in your Django app's settings. By default this is/media/
, so in your web root folder, create a symlink calledmedia
to/usr/lib/python2.5/site-packages/django/contrib/admin/media
. (Note the trailingmedia
on the end of the symlink, which is missing from your own example -- the Django admin media is located in amedia
subdirectoryin
contrib/admin`).Apache Alias
If your production server is Apache, and you can change the root configuration, you can use
mod_alias
to set up the path to Django admin media. Again, assuming that yourADMIN_MEDIA_PREFIX
is/media/
, you can set up an alias like so:This way, all requests under the path
/media/
will be resolved to that directory.A similar technique exists for most other servers, such as Lighttpd or nginx; consult your server's documentation if you don't use Apache.
The solution using Apache's
mod_alias
is probably best for deployment, but the symlinking approach works just as well too.The reason your app worked on your staging server is most likely because it was running with Django's internal web server, which can automatically resolve the path to the admin media directory.
我认为您以错误的方式创建了符号链接 - 您的命令在 ..../contrib/admin/ 中创建了一个
htdocs
符号链接,您需要的是类似
Where
X 是访问 ADMIN_MEDIA_PREFIX 所需的任何内容。我认为默认值是
admin/media
希望有帮助
I think you've created the symlink the wrong way round - your command has created a
htdocs
symlink in ..../contrib/admin/What you need is something like
Where
X
is whatever you need to get to your ADMIN_MEDIA_PREFIX. I think the default would beadmin/media
Hope that helps