0

I'm trying to serve user-uploaded images locally on Django 1.10. I'm following the documentation here and getting this error:

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.

The issue is from adding the static portion of my urls:

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

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

When I remove the static addition to my urls, the error goes away. What am I doing wrong here?

My applicable settings are as follows:

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/"
YPCrumble
  • 26,610
  • 23
  • 107
  • 172

1 Answers1

0

The answer is that static should not be inside a list. This line:

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

should be:

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
YPCrumble
  • 26,610
  • 23
  • 107
  • 172