Ensure that urlpatterns is a list of path() and/or re_path() instances

Submitted 3 years, 6 months ago
Ticket #195
Views 1663
Language/Framework Django
Priority Low
Status Closed

My urlpatterns :

urlpatterns = [
    re_path(r'^dj-admin/', admin.site.urls),
    re_path(r'^admin/', include(wagtailadmin_urls)),
    re_path(r'^docs/', include(wagtaildocs_urls)),

    i18n_patterns(
        path(r'', include(wagtail_urls)),
        prefix_default_language = False
    )
]

ERRORS:
?: (urls.E004) Your URL pattern [ (None:None) ''>] is invalid. Ensure that urlpatterns is a list of path() and/or re_path() instances.

To my best understanding it is equivalent to the example in the docs:

urlpatterns = [
    path('sitemap.xml', sitemap, name='sitemap-xml'),
]

urlpatterns += i18n_patterns(
    path('about/', about_views.main, name='about'),
)

BTW:

In [1]: import django

In [2]: django.__version__
Out[2]: '2.0.5'
Submitted on Oct 04, 20
add a comment

1 Answer

Verified

just convert any tuples

urlpatterns = [
    (r'^$', home, name='home'),  # tuple
]

to url() instances:

urlpatterns = [
    url(r'^$', home, name='home'),  # url instance
]

If you get the following NameError,

NameError: name 'url' is not defined

then add the following import to your urls.py:

from django.conf.urls import url

Submitted 3 years, 6 months ago


Latest Blogs