Home > Blockchain >  Need to have the correct url path in Django
Need to have the correct url path in Django

Time:05-06

I am trying to get my django app to point to the correct url in my chatserver/urls.py file.

I am getting this error when I start my django app:

Using the URLconf defined in chatserver.urls, Django tried these URL patterns, in this order:

admin/ join [name='join'] The empty path didn’t match any of these.

This is my chatserver/urls.py file:

from django.contrib import admin
from django.urls import path, include
urlpatterns = [
    path('', include('chat.urls')),
    path('admin/', admin.site.urls),
]

And this is my chat/urls.py file:

from django.urls import path
from . import views

urlpatterns = [
    path('join', views.init, name='join'),
]

And here is my app project directory:

directory structure

[1] Can someone help me correct my error?

CodePudding user response:

I would provide a name for my app in chat/urls.py

from .views import init

app_name = 'chat'
urlpatterns = [
    path('join', view=init, name='join'),
]

then for my chatserver/urls.py provide a namespace for each path

urlpatterns = [
    path('', include('chat.urls', namespace='chat')),
]
  • Related