This has been asked before, but the problems were usually with placement of the mysite/urls.py or missing text somewhere. I've gone over those in detail, but doesn't apply here. I'm following the django tutorial EXACTLY, which means it hasn't referenced including the polls app in the settings.py file. I can pull up the right view if I manually type in the "polls" at the end of the url, as in "http://127.0.0.1:8000/polls" but I shouldn't have to do this for it to work. I'm also assuming the tutorial isn't wrong in some way. Link to the tutorial is: https://docs.djangoproject.com/en/1.9/intro/tutorial01/
The error I get:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, , didn't match any of these.
My views.py file:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
My polls/urls.py file:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
My mysite/mysite/urls.py file:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
This is the tree for the mysite/mysite directory just to show that I am in the right folder (there is no separate urls.py file in the main mysite directory):
.
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-35.pyc
│ ├── settings.cpython-35.pyc
│ ├── urls.cpython-35.pyc
│ └── wsgi.cpython-35.pyc
├── settings.py
├── urls.py
└── wsgi.py
Again, best I can tell this is to the letter following the django tutorial guidance. I'd like to fix it, but more importantly understand why it isn't working.
/polls/. This is defined in your main urls.py. If you want to change it...you should be using:url(r'', include('polls.urls')),- rnevius