移动静态文件夹时出现问题

发布于 2024-11-29 09:29:10 字数 1120 浏览 4 评论 0原文

我在将 django 应用程序上传到 dotcloud 时遇到问题。我使用下面的代码将 django 的管理面板静态文件更改为 /static/admin_media,但在部署时出现以下错误:

2011-08-14 13:22:35 [www.0] Traceback (most recent call last):
2011-08-14 13:22:35 [www.0]   File "./postinstall", line 23, in <module>
2011-08-14 13:22:35 [www.0]     os.symlink(mediadir, staticlink)
2011-08-14 13:22:35 [www.0] OSError: [Errno 2] No such file or directory

和代码:

import os
# To import anything under django.*, we must set this variable.
os.environ['DJANGO_SETTINGS_MODULE'] = 'kalvin.settings'
# Import the admin module. The media directory is right under it!
import django.contrib.admin
# Retrieve the absolute path of the admin module.
admindir = os.path.dirname(django.contrib.admin.__file__)
# Add /media behind it.
mediadir = os.path.join(admindir, 'media')
# Compute the path of the symlink under the static directory.
staticlink = os.path.join('static', 'admin_media')
# If the link already exists, delete it.
if os.path.islink(staticlink):
    os.unlink(staticlink)
# Install the correct link.
os.symlink(mediadir, staticlink)

I have a problem with uploading a django app to dotcloud. I'm using the code below to change django's admin panel static files to /static/admin_media, but it gives me the following error when deploying:

2011-08-14 13:22:35 [www.0] Traceback (most recent call last):
2011-08-14 13:22:35 [www.0]   File "./postinstall", line 23, in <module>
2011-08-14 13:22:35 [www.0]     os.symlink(mediadir, staticlink)
2011-08-14 13:22:35 [www.0] OSError: [Errno 2] No such file or directory

and the code:

import os
# To import anything under django.*, we must set this variable.
os.environ['DJANGO_SETTINGS_MODULE'] = 'kalvin.settings'
# Import the admin module. The media directory is right under it!
import django.contrib.admin
# Retrieve the absolute path of the admin module.
admindir = os.path.dirname(django.contrib.admin.__file__)
# Add /media behind it.
mediadir = os.path.join(admindir, 'media')
# Compute the path of the symlink under the static directory.
staticlink = os.path.join('static', 'admin_media')
# If the link already exists, delete it.
if os.path.islink(staticlink):
    os.unlink(staticlink)
# Install the correct link.
os.symlink(mediadir, staticlink)

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

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

发布评论

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

评论(1

小红帽 2024-12-06 09:29:10

解决方案是这个答案

我需要一个名为 static 的空文件夹,但 git 没有将其传输到服务器,因为它是空的。

在文件夹内创建 .gitignore 解决了问题。

The solution is this answer.

I needed an empty folder named static, but git didn't transfer it to the server because it was empty.

Creating .gitignore inside the folder fixed the problem.

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