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:
Create your views here.
from django.http import HttpResponse
return HttpResponse(“Hello, world. You’re at the polls index.”)
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 = [
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/ are two different urls.
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
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
I’ve just checked that going to
localhost:8000/poll redirects me to
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
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
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.