Home > Blockchain >  Your URL pattern [<URLPattern> ] is invalid. DJANGO Urls.py file
Your URL pattern [<URLPattern> ] is invalid. DJANGO Urls.py file

Time:10-20

I am getting this error:

ERRORS:
app_1 | ?: (urls.E004) Your URL pattern [<URLPattern '^static/media/(?P<path>.*)$'>] is invalid. Ensure that urlpatterns is a list of path() and/or re_path() instances.
app_1 | ?: (urls.E004) Your URL pattern [<URLPattern '^static/static/(?P<path>.*)$'>] is invalid. Ensure that urlpatterns is a list of path() and/or re_path() instances.

I don't know why I am getting this error. I have correctly added everything in my url patterns

urlpatterns = [
  path("admin/", admin.site.urls),
  path("api/v1/jobs/", include("jobs.urls")),
  path("api/v1/company/", include("company.urls")),
]

if settings.DEBUG:
  urlpatterns.extend(
     [
        static("/static/static/", document_root="/vol/web/static"), 
        static("/static/media/", document_root="/vol/web/media"),
        path("__debug__/", include(debug_toolbar.urls)),
    ]
)

CodePudding user response:

The function static() returns a list already, not a single pattern. It could be that the list contains a single path element, but it is a list nonetheless.

I suggest you change your code to:

if settings.DEBUG:
    # add multiple paths using 'extend()'
    urlpatterns.extend(static("/static/static/", document_root="/vol/web/static"))
    urlpatterns.extend(static("/static/media/", document_root="/vol/web/media"))

    # add a single path using 'append()'
    urlpatterns.append(path("__debug__/", include(debug_toolbar.urls)))
  • Related