0

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

2 Answers 2

2

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.

2
  • 1
    i knew its some trivial typo, thanks indeed thats the case , its kind of not intuitive that you have to add that slash
    – WKordos
    Jul 28, 2020 at 22:43
  • 1
    @Wkordos: well sometimes it might be wanted to not have a slash between the TEST1 and TEST :). But I agree it is not very common. Jul 28, 2020 at 22:44
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.