尝试在本地提供用户上传的文件时出错

Error trying to serve user uploaded files locally

我正在尝试在 Django 1.10 上本地提供用户上传的图像。我正在关注 the documentation here 并收到此错误:

SystemCheckError: System check identified some issues:
Your URL pattern [<RegexURLPattern None ^media\/(?P<path>.*)$>] is invalid. 
Ensure that urlpatterns is a list of url() instances.

问题来自添加我的网址的 static 部分:

urlpatterns = [
    ...my urls...
]

if settings.DEBUG:
    # This is causing the error.
    urlpatterns += [
        static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    ]

当我删除网址中的 static 附加项时,错误消失了。我在这里做错了什么?

我适用的设置如下:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_ROOT = BASE_DIR + "/static/"
STATIC_URL = "/static/"
MEDIA_ROOT = BASE_DIR + "/media/"
MEDIA_URL = "/media/"

答案是 static 不应该在列表中。这一行:

urlpatterns += [
    static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
]

应该是:

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)