我试图在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/"
答案 0 :(得分:0)
答案是static
不应该在列表中。这一行:
urlpatterns += [
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
]
应该是:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)