Django admin 没有样式

发布于 2024-08-13 01:34:43 字数 233 浏览 3 评论 0原文

我刚刚将我的 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 技术交流群。

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

发布评论

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

评论(2

记忆里有你的影子 2024-08-20 01:34:43

根据您的 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/,您可以像这样设置别名:

<VirtualHost *:80>
  Alias /media/ /usr/local/lib/python2.5/site-packages/django/contrib/admin/media/
</VirtualHost>

这样,路径 /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 called media to /usr/lib/python2.5/site-packages/django/contrib/admin/media. (Note the trailing media on the end of the symlink, which is missing from your own example -- the Django admin media is located in a media subdirectoryincontrib/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 your ADMIN_MEDIA_PREFIX is /media/, you can set up an alias like so:

<VirtualHost *:80>
  Alias /media/ /usr/local/lib/python2.5/site-packages/django/contrib/admin/media/
</VirtualHost>

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.

梦里泪两行 2024-08-20 01:34:43

我认为您以错误的方式创建了符号链接 - 您的命令在 ..../contrib/admin/ 中创建了一个 htdocs 符号链接,

您需要的是类似

sudo ln -s /usr/lib/python2.5/site-packages/django/contrib/admin/ /var/www/sico/htdocs/X

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

sudo ln -s /usr/lib/python2.5/site-packages/django/contrib/admin/ /var/www/sico/htdocs/X

Where X is whatever you need to get to your ADMIN_MEDIA_PREFIX. I think the default would be admin/media

Hope that helps

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