I am running a django project on a ubuntu digital ocean droplet with nginx/gunicorn on my own domain. I am using a virtual environment with Django version 3.1.6 and Python 3.8.5
I am trying to follow Corey Shafers Django tutorial to create a blog app and while I can reach the generic django success page on example.com I ran into the following from example.com/blog :
Page not found (404)
Request Method: GET
Request URL: example.com/blog
Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
admin/
The current path, blog, didn’t match any of these.
My current ~/projectdir/website/urls.py (see edit at bottom):
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/',admin.site.urls),
path('', include('blog.urls')),
]
My ~/projectdir/blog/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='blog-home'),
path('about/', views.about, name='blog-about'),
]
My ~/projectdir/blog/views.py:
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse('<h1>Blog Home</h1>')
As far as I can tell everything looks ok syntax-wise but I can’t figure out why the URLconf is not seeing the blog path. I have tried reloading nginx and that didn’t help.
EDIT
I have edited /projectdir/website/urls.py to look like this:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/',admin.site.urls),
path('blog', include('blog.urls')),
]
I am still getting the same 404 reponse with "The current path, blog, didn’t match any of these."
3
Answers
I think you have not included the blog app in your base urls.py, see this django doc.
Your virtual environment may not be enabled in Visual Studio code. Activate venv in vscode or other , then try again
you can activate venv in vscode by ctrl+shift+P -> select interpreter ->Select Interpreter path -> select your python that you want use it.
or you dont run your project in vscode and then run it
and then /polls request after localhost:8000 to the correct address will do
path('', include('blog.urls'))
urls paths should written aspath('blog/', include('blog.urls'))
.This mean
include path
not be an empty string.