Search code examples
reactjsdjango

Django is saying that the url doesn't match itself


from django.urls import path
from .views import index

urlpatterns = [

    path('', index),
    path('/join', index),
    path('/create', index)
    
]
Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/join
Using the URLconf defined in music_controller.urls, Django tried these URL patterns, in this order:

admin/
api/
/join
/create
The current path, join, didn’t match any of these. "

someone please tell me how join doesn't match join? thank you.


Solution

  • You should not prepend the path with a leading slash, so:

    urlpatterns = [
        # …,
        path('join/', join),
        # …
    ]

    not:

    urlpatterns = [
        # …,
        path('/join', join),
        # …
    ]

    you probably also want to add an trailing slash, although not required, Django's paths typically end with a trailing slash, and if no path matches, and the APPEND_SLASH setting [Django-doc] is set to True, it will try to redirect to a path with a trailing slash.