Question:
Django Issue Solved: path searched will not match URL patterns

Problem

I am new to Django following a tutorial, but cannot get past this error message from Django. I am typing in the file path exactly, but it will not work.


Here are the website URLs .py:


from django.contrib import admin

from django.urls import path, include


urlpatterns = [

    path("admin/", admin.site.urls),

    path("hello/", include('testApp.urls')),

]


Here is the app's urls .py:


from django.urls import path 

from . import views


urlpatterns = [

    path('hello/', views.say_hello)

]


Here is the app's view.py


from django.shortcuts import render

from django.http import HttpResponse


def say_hello(request): 

    return HttpResponse("Bernz/Shell Boat Parts")


--Thank you.

I've tried >http://127.0.0.1:8000/hello and >http://127.0.0.1:8000/testAPP/hello and both have given me the same message that they do not match. Please help:



Solution

You should visit /hello/hello/, the first one from the path("hello/", include('testApp.urls')), and the second from the path('hello/', views.say_hello).

Likely however you want to remove the second one, so:


# testApp.urls


urlpatterns = [path('', views.say_hello)]


then it is /hello/


Note: Django's apps normally are written in snake_case, so test_app, not testApp.


Nisha Patel

Nisha Patel

Submit
0 Answers