I am new to Django and learning this python framework. I have created a virtual environment called Virtual_Django_Project and installed Django in it. Moving ahead I created folder called Django_project and added an app called blog you can see my files here File Directories. Error >Page not found at /blog/
blog.views.py Code
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse('Home')
blog.urls.py Code
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name ='blog-home'),
]
Main Django_Project.urls Code
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('blog.urls')),
]
Can anyone tell me why my blog page is not opening and showing the error page not found?
PS: Server is running in cmd.
CodePudding user response:
Ok so I guess, based on your screenshot it seems to look like only your admin page is properly registered.
It is very simple, just go to settings.py in project and make sure you added your apps in installed apps.
INSTALLED_APPS = [
...
"app name"
then clearly you have added urls.py in app but you have to add in project urls.py too... If you forgot it add it too...
urlpatterns = [
path('blog/', include('app name.urls', namespace='app name')),
- namespace is not a must to add.
I guess that should be the error...
CodePudding user response:
There is no path
found in your blog
app. It seems that simply you have not specified "blog"
in your INSTALLED_APPS
. Pretty common mistake after creating a new app in a Django's project. Add it so Django would be able to find that view.