django不显示来自MEDIA的图像

时间:2017-05-16 08:58:34

标签: django

这是我的网址:

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 \静态\ FOLDER_NAMES

当debug为True时,图像工作正常,但当我将其变为False时,只显示来自{%static%}的图像。剩下的就是404。

1 个答案:

答案 0 :(得分:0)

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