Django Tutorial Will not work

I am following the tutorial, and it is not working no matter what I try. I am at the end of the 1st part of the tutorial, but every time I try running http://127.0.0.1:8000/polls it just does not work and says admin is the only URL that shows. I have tried many fixes from other posts, but it is not working.
mysite/mysite/urls has the code from the tutorial, and i filled out polls/views and polls/urls. I have deleted all my files and restarted the tutorial a few times, but it is not working. Here is the code I have:
polls/views.py:

Create your views here.

from django.http import HttpResponse

def index(request):
return HttpResponse(“Hello, world. You’re at the polls index.”)
polls/urls.py:
from django.urls import path

from . import views

urlpatterns = [
path(“”, views.index, name=“index”),
]
my site urls:
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path(“polls/”, include(“polls.urls”)),
path(“admin/”, admin.site.urls),
]
path
idk if that works but it shows how the files are placed. I do not know what else to try so any help would be appreciated. Thank you

Your url path includes the trailing slash for the url polls/, but you aren’t showing it in the url that you’re saying that you are trying. Yes, polls and polls/ are two different urls.

1 Like

Sorry that was unclear, I have tried polls/ as well, but neither seem to work, and when on the 404 error page it only says that admin/ is a URL present it does not even show polls

What OS are you working on? Have you stopped and restarted the server? What is the ROOT_URLCONF setting in your settings.py file?

Windows. My root_urlconf just says mysite.urls

I’ve to say I’m pretty intrigued about that error. I just did that first section of the tutorial on two UNIX machines, and they both worked. Unfortunately, I don’t have a Windows machine at hand right now.

Can you put that code on a public repository and share the link?

Have you added the polls app in INSTALLED_APPS in settings.py

Wow this is weird, but I just tried the same thing on my computer without adding the polls app in the INSTALLED_APPS in the settings.py and this is working

Mr. Ken, will not django redirects polls to polls/

I’ve just checked that going to localhost:8000/poll redirects me to localhost:8000/polls/

C:\Users\home\Desktop\mysite>curl localhost:8000/polls -v
*   Trying 127.0.0.1:8000...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET /polls HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Sat, 26 Aug 2023 05:21:35 GMT
< Server: WSGIServer/0.2 CPython/3.10.9
< Content-Type: text/html; charset=utf-8
< Location: /polls/
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Cross-Origin-Opener-Policy: same-origin
< Connection: close
<
* Closing connection 0

It’s a configuration setting, it doesn’t “automatically “ do that. So without diving into those settings, I don’t assume it’s going to be there. See Settings | Django documentation | Django

1 Like

But in the global settings the APPEND_SLASH is already set to true

It also requires the common middleware to be installed. Yes, it’s also a default for startproject, but would need to be verified.

I will do that now let me get one up

https://github.com/Alex-Aron/djangotutorial
That link has my files

The mysite.urls file you posted in that repo only has the admin entry. It does not have the polls entry. Your polls.urls file is also empty.

Oh my god. The issue was that the files I was typing was not properly saving when I hit control S, so when I put it to git it just pushed empty files. All the code I typed was not saved that’s why nothing was working.

2 Likes

Oh man I just want to thank you for taking the time to post that you have no idea how much you have helped me i have been going crazy for 5 hours not knowing why none of my code was running turns out I wasnt saving anything lmao hadnt even thought of that until I read you comment

1 Like

This error is in index.html.
You have to change code to original code.
There causes by reverse error.
It works well.