in urls.py
file my code is:
from django.urls import path
from . import views
urlpatterns = [
path("<str:name>", views.index ,name="index"),
]
in views.py
file my code is:
from django.shortcuts import render
from django.http import HttpResponse
from .models import ToDoList, Item
# Create your views here.
def index(response,name):
ls=ToDoList.objects.get(name=name)
return HttpResponse("<h1>%s</h1>" %ls.name)
path also added in urls.py-mysite
error showing page not found
CodePudding user response:
You need to include your app urls.py into your project urls.py like this:
from django.urls import path, include
urlpatterns = [
path("", include("your_app.urls")),
]
CodePudding user response:
Assuming you're running this from an app, don't forget to add your app to your settings.py file as well, such that:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app' # add the name of your app here
]
and your project urls.py
file should also look like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app.urls')) # add your app name here as well
]