【问题标题】:django does not show images from MEDIAdjango 不显示来自媒体的图像
【发布时间】:2017-10-15 06:17:31
【问题描述】:

这是我的网址:

urlpatterns = [
url(r'^', include('my_website.urls')),

url(r'^tinymce/', include('tinymce.urls')),
url(r'^filer/', include('filer.urls')),
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
url(r'^admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT + os.path.altsep )

这是我的设置:

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG           = False
ALLOWED_HOSTS   = ['localhost', '127.0.0.1']


MEDIA_ROOT  = os.path.join(BASE_DIR, "mooimom_id", "user_uploads")
MEDIA_URL   = "/media/"

我的媒体文件都在:

C:\wamp64\www\mooimom_django\mooimom_id\user_uploads\folder_name\file_names

静态文件主要位于: C:\wamp64\www\mooimom_django\mooimom_id\static\folder_names

当 debug 为 True 时,图像工作正常,但当我将其变为 False 时,仅显示来自 {% static %} 的图像。其余的得到 404。

【问题讨论】:

  • 这是本地主机(我自己的计算机),还没有在实时服务器中
  • 对不起,我不明白你的问题,我对 Django 很陌生
  • 我不明白,我需要做什么?
  • 谢谢,不过我的 django 不使用 wamp,我只是将所有项目都放在那个文件夹中,我的网络服务器是 pycharm 2017
  • 我在pycharm上使用“运行”和“调试”,

标签: django


【解决方案1】:

正如documentation for the static helper 明确指出的那样,这仅在 DEBUG 为 True 时有效。

【讨论】:

  • 但我的静态文件工作正常,是媒体文件夹中的文件没有显示/404
  • 这在 DEBUG false 上不起作用:127.0.0.1:8000/media/filer_public/93/3e/…
  • 因为我想将文件上传到网络服务器。
  • 对不起,我对 django 很陌生,我想做的是确保我的网站即使在 DEBUG 为 False 时也能正常工作,当 DEBUG 为 true 时我的网站已经在工作了。
  • 但是当 DEBUG 为 false 时,媒体文件都得到 404,但来自 {% static %} 的图像有效。
猜你喜欢
  • 1970-01-01
  • 2017-01-11
  • 2021-10-12
  • 2017-07-08
  • 2011-07-21
  • 1970-01-01
  • 1970-01-01
  • 2015-05-07
  • 2015-01-08
相关资源
最近更新 更多