1

I'm a complete Django newbie and I am following the tutorial:

https://docs.djangoproject.com/en/1.11/intro/tutorial01/

I have got to the stage:

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), ] 

in mysite/urls.py, but when I do:

python manage.py runserver 

I get a 404 error in the browser at the address

http://localhost:8000/polls/ 

I am using python 2.7.6 and Django 1.11.5

My urls.py is

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), ] 

In the terminal session I get

Not Found: /polls/ [05/Oct/2017 12:25:22] "GET /polls/ HTTP/1.1" 404 1951 

when I load the web page in the browser

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

Can someone please point out what might be wrong?

3
  • What's in polls/urls.py? Commented Oct 5, 2017 at 10:07
  • please post your urls.py Commented Oct 5, 2017 at 11:14
  • @Psionman - Hope you added polls under INSTALLED_APPS in the settings.py Commented Oct 5, 2017 at 12:15

2 Answers 2

1

on mysite/settings.py add in INSTALLED_APPS:

INSTALLED_APPS = [ ...<other installed apps>.. 'polls', ] 

for latest django versions it is recommeded to add:

INSTALLED_APPS = [ ...<other installed apps>.. 'polls.apps.PollsConfig', ] 

Put in mysite/urls.py(the one you posted here):

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), ] 

And in polls/urls.py::

from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ] 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. just adding 'polls' does nothing. There is no PollsAuthConfig class in polls.apps, but there is PollsConfig. If I include PollsConfig it gives "application labels aren't unique ..." error
@Psionman what is polls/urls.py, you have posted here is mysite/urls.py
No. That is in .../polls/
OK. Solved it thanks. Didn't realise there were two urls.py (confusing for a newbie)
0

clear answer for beginners who has this issue by following the tutorial here, the project root URLconf is the one in the same folder as settings.py which is:

mysite/mysite/urls.py 

Just make sure import 'include'. The code looks like:

from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^polls/', include('polls.urls')), ] 

So in mysite/mysite/settings.py:

The line should be:

ROOT_URLCONF = 'mysite.urls' 

You don't need create a fresh new root URLconf.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.