Home > database >  Trouble with routing in django - page not found
Trouble with routing in django - page not found

Time:03-19

I am not able to perform routing.

error at /home: [enter image description here]

urls.py:
from django.contrib import admin
from django.urls import path

from app.views import views

urlpatterns = [
    path('home/', views.home_view, name='home'),
    path('admin/', admin.site.urls),
]

views.py:

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

def home_view(*args, **kwargs):
    return HttpResponse("<h1>Hello World<h1>")

CodePudding user response:

From the limited information (at the time of writing this answer) provided by OP, it seems the django app app is not registered in INSTALLED_APPS

From the images, it seems the project is structured like this

project/
├── app
│   ├── __init__py
│   └── views.py
├── asgi.py
├── __init__.py
├── manage.py
├── settings.py
├── urls.py
└── wsgi.py

You need to add app in the INSTALLED_APPS list in your settings.py

INSTALLED_APPS = [
...
'app',
...
]

This activates your sub-app app to be used in your django project.

CodePudding user response:

the import in urls.py should be

from app import views

but it is difficult to judge without the full error message

  • Related