django,runserver_plus - 从错误路径提供的管理媒体文件

发布于 2024-08-16 10:26:00 字数 861 浏览 2 评论 0原文

下面的配置在我的远程主机上运行良好(相同的目录结构,相同的 django),所有管理媒体均正确

设置

MEDIA_ROOT = '%s/static/' % FS_ROOT
STATIC_DOC_ROOT = '%s/static/' % FS_ROOT
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '%smedia/' % MEDIA_URL

urls

(r'^admin/', include(admin.site.urls)),
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': '%s/static' % FS_ROOT }),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': '%s/media' % FS_ROOT }),

django 1.2.0 @ ubuntu 9.10, http://127.0.0.1:8084/ 通过 runserver_plus

管理媒体文件存储在我的项目根目录中的 /static/media/ 下,每个静态文件/目录存储在 /static/ 下。所有静态服务都很好,只有管理媒体是从默认的 django 管理媒体文件中获取的。我忘记了什么以及为什么它只影响我的本地主机上的项目?我尝试过以各种方式在 url 中使用 /static/media/ 路径,但仍然一无所获。

The configuration below works fine on my remote host (same dir structure, same django), all admin media are served properly

settings

MEDIA_ROOT = '%s/static/' % FS_ROOT
STATIC_DOC_ROOT = '%s/static/' % FS_ROOT
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '%smedia/' % MEDIA_URL

urls

(r'^admin/', include(admin.site.urls)),
(r'^static/(?P<path>.*)

django 1.2.0 @ ubuntu 9.10, http://127.0.0.1:8084/ via runserver_plus

Admin media files are stored under /static/media/ in my project root dir and every static files/dirs under /static/. All statics are served fine, only the admin media are taken from the default django's admin media files. What am I forgetting and why it does affect the project only on my localhost? I've tried to everride /static/media/ path in the urls in various ways, but still nothing.

, 'django.views.static.serve', {'document_root': '%s/static' % FS_ROOT }), (r'^media/(?P<path>.*)

django 1.2.0 @ ubuntu 9.10, http://127.0.0.1:8084/ via runserver_plus

Admin media files are stored under /static/media/ in my project root dir and every static files/dirs under /static/. All statics are served fine, only the admin media are taken from the default django's admin media files. What am I forgetting and why it does affect the project only on my localhost? I've tried to everride /static/media/ path in the urls in various ways, but still nothing.

, 'django.views.static.serve', {'document_root': '%s/media' % FS_ROOT }),

django 1.2.0 @ ubuntu 9.10, http://127.0.0.1:8084/ via runserver_plus

Admin media files are stored under /static/media/ in my project root dir and every static files/dirs under /static/. All statics are served fine, only the admin media are taken from the default django's admin media files. What am I forgetting and why it does affect the project only on my localhost? I've tried to everride /static/media/ path in the urls in various ways, but still nothing.

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

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

发布评论

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

评论(1

天生の放荡 2024-08-23 10:26:00

有两种解决方案:

  1. 您可以按照 此答案中的建议在 ADMIN_MEDIA_PREFIX 中设置主机名
  2. 或者您可以使用 --adminmedia 参数启动开发服务器,如 django 文档

There are two solutions:

  1. You can either set a hostname in ADMIN_MEDIA_PREFIX as suggested in this answer.
  2. Or you can start the development server with the --adminmedia parameter as described in the django documentation.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文