Katie Melosto
Katie Melosto

Reputation: 1177

Django 404 error even though I've created the path and view

I'm just beginning to learn Django. I've created a simple web sub-app called 'flavo' inside of another one called 'djangoTest' When I run http://127.0.0.1:8000/flavo it correctly displays Hello, World! then when I run http://127.0.0.1:8000/flavo/a it should show Hello, a! But instead I get:

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/flavo/a
Using the URLconf defined in testDjango.urls, Django tried these URL patterns, in this order:

admin/
flavo [name='index0']
flavo a [name='a']
The current path, flavo/a, didn’t match any of these.

in testDjango/hello/views.py I have

from django.http import HttpResponse
from django.shortcuts import render

def index0(request):
    return HttpResponse("Hello, world!")

def a(request):
    return HttpResponse("Hello, a!")

In testDjango/flavo/url/py I have

from django.urls import path

from . import views

urlpatterns = [
    path("", views.index0, name="index0"),
    path("a", views.a, name="a"),
]

The only other file I've changed is , testDjango/testDjango/urls.py"

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('flavo', include("flavo.urls")),
]

I'm confused why I can't access http://127.0.0.1:8000/flavo/a

Upvotes: 0

Views: 344

Answers (1)

hs2
hs2

Reputation: 84

Add '/'.

like this.

# testDjango/testDjango/urls.py
path('flavo/', include("flavo.urls"))

Upvotes: 1

Related Questions