Django 1.3 - 简单的媒体部署

发布于 2024-10-30 08:45:44 字数 783 浏览 1 评论 0原文

我在让 django 与我的媒体设置良好配合时遇到了一些真正的困难。我没有使用静态文件,因为在项目的这个阶段我不需要 CDN,并且我想保持简单。

我的文件夹结构如下所示:

/static
    /admin
        /css
        /js
        /etc
    /css
    /js
    /images

admin 文件夹是 admin contrib 媒体文件夹的副本...因为我使用的是 mod_wsgi 我知道它不能存在于 django 项目文件夹中。

我的设置文件:

MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static/')
MEDIA_URL = 'http://127.0.0.1:8000/static/'
ADMIN_MEDIA_PREFIX = 'admin/' (tried with leading slash too)

URL:

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

无论我尝试什么,我都无法让管理媒体提供服务。通过阅读文档我知道 ADMIN_MEDIA_PREFIX 必须与普通媒体 url 非常不同,但由于 mod_wsgi,我需要能够在系统 django 文件夹之外提供文件。

有人可以帮忙吗?

I having some real trouble getting django to play nice with my media setup. I am not using staticfiles since I am have no need for a CDN at this point of the project and I want to keep it simple.

My folder structure looks like this:

/static
    /admin
        /css
        /js
        /etc
    /css
    /js
    /images

The admin folder is a copy of the admin contrib media folder... since I am using mod_wsgi I know that this can't live in the django project folder.

My settings file:

MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static/')
MEDIA_URL = 'http://127.0.0.1:8000/static/'
ADMIN_MEDIA_PREFIX = 'admin/' (tried with leading slash too)

Urls:

(r'^static/(?P<path>.*)

No matter what I try, I can't get the admin media to serve. I know from reading the documentation that the ADMIN_MEDIA_PREFIX has to be very different from the normal media url, but I need to be able to serve the files outside of the system django folder because of mod_wsgi.

Can anyone help?

, 'django.views.static.serve', {'document_root':MEDIA_ROOT, 'show_indexes':True}),

No matter what I try, I can't get the admin media to serve. I know from reading the documentation that the ADMIN_MEDIA_PREFIX has to be very different from the normal media url, but I need to be able to serve the files outside of the system django folder because of mod_wsgi.

Can anyone help?

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

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

发布评论

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

评论(1

も让我眼熟你 2024-11-06 08:45:44

对于您的设置,ADMIN_MEDIA_PREFIX = MEDIA_URL + 'admin/' 应该有效。

For your setup, ADMIN_MEDIA_PREFIX = MEDIA_URL + 'admin/' should work.

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