Home > Software engineering >  Django tutorial problem: The current path, polls/, didn’t match any of these
Django tutorial problem: The current path, polls/, didn’t match any of these

Time:12-08

I'm just getting started with Django, and I'm a touch rusty with web development, so this may be an easy one. I'm stepping through the Django Polls Tutorial from the official documentation and I encounter a problem nearly right away. I'm not having success accessing http://localhost:8000/polls/ . I receive the error...

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

admin/ The current path, polls/, didn’t match any of these.

Here is my relevant code...

\mysite\polls\views.py

from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

\mysite\polls\urls.py

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

\mysite\urls.py

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

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

\mysite\mysite\setting.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
ROOT_URLCONF = 'mysite.urls'

Development server reads...

Not Found: /polls/ [06/Dec/2022 15:02:01] "GET /polls/ HTTP/1.1" 404 2095

I have tried a hodgepodge of fixes that I've seen from other similar tutorial fixes, but nothing has worked and I feel like I'm taking stabs in the dark at this point.

Thank you Hash & Carlos for taking a look. I modified as suggested, and restarted server, but I get the exact same result...

\mysite\mysite\settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
]

I feel as though there is a simple path error occurring somehow. Could there have been an error in my django setup? I do see the spaceship at localhost:8000, as I should.

CodePudding user response:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
]

you are written the code correclty but you need to add your apps in intalled apps in settings.py file

CodePudding user response:

I deleted my project, and my virtual environment(ok because this was the only thing in it), and started over from scratch. This time I was successful. I'm not completely sure why. It is not clear to me where the problem was, but I am ok moving on to bigger and better challenges. Ty for your responses!

BTW: I did not have to add "polls" to the settings.py file, which is consistent with the tutorial

  • Related