WKordos
WKordos

Reputation: 2245

problem with django url dispatcher , unable to resolve the url

i got latest django installed and working through hello world tutorial

i got problem with getting url dispatcher working

i got configured as follow in django_web/urls.py i got

urlpatterns = [
    path('TEST1', include('newpage.urls')),
    #path('admin/', admin.site.urls),
]

in newpage/urls.py i got

urlpatterns = [
        path('', views.index, name='index'),
        path('TEST' ,views.index2, name='cokolwiek'),
        ]

if i hit localhost:8000/TEST1 - works fine

if i hit localhost:8000/TEST1/TEST - does not work i got followin message

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

TEST1 [name='index']
TEST1 TEST [name='cokolwiek']
The current path, TEST1/TEST, didn't match any of these.

how the hell is that not working

Upvotes: 0

Views: 442

Answers (2)

Otee
Otee

Reputation: 108

under urls.py add: path(' ', include('newpage.urls')),

urlpatterns = [
    path(" ",view.page,name="homepage.urls"),
    #path('admin/', admin.site.urls),
]

#In the main app open views.py

from django.http import HttpResponse

#Under create views here type:

def homepage(request)

Upvotes: 0

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476503

You did not use a slash, hence the path is localhost:8000/TEST1TEST. But likely you do not want that. You likely want to add a slash after the TEST1:

urlpatterns = [
    path('TEST1/', include('newpage.urls')),
]

this is also the reason why admin/ is used. Django will normally first try the patterns, and if that did not resolve anything try to append a slash and tries the paths again. This is the effect of the APPEND_SLASH setting [Django-doc]. But this is only done at the end of the full path. So it does not mean it adds a slash at the patterns.

Upvotes: 2

Related Questions