Error running Django tutorial

12,442 views
Skip to first unread message

Mike Kipling

unread,
Feb 27, 2016, 2:50:39 PM2/27/16
to Django users
I am working through the Django tutorial Writing your first Django app, part 1.
I am using Windows 10, python 3.5.1 and Django 1.9.2 .
 
In the Write your first view section: 
    after writing the polls/views.py and polls/urls.py files,
    and modifying the manage/urls.py file,
    and starting the server,
 
    When I go to http://localhost:8000/polls/ in the browser I get the following 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:

  1. ^admin/

The current URL, polls/, didn't match any of these.

James Schneider

unread,
Feb 27, 2016, 3:06:42 PM2/27/16
to django...@googlegroups.com

It doesn't appear that you've included your apps urls.py correctly using an include() in your project urls.py.

Can you post both of your urls.py files?

-James

Message has been deleted

Mike Kipling

unread,
Feb 28, 2016, 10:15:24 AM2/28/16
to Django users
Here are the two urls.py files:

polls/urls.py

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

mysite/urls.py

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

Mike

Igor Makarov

unread,
Feb 28, 2016, 3:29:32 PM2/28/16
to Django users
Mike, do you have the server restarted? 
As for me, the shell window says: 
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.



воскресенье, 28 февраля 2016 г., 18:15:24 UTC+3 пользователь Mike Kipling написал:
Message has been deleted

Mike Kipling

unread,
Feb 28, 2016, 10:11:26 PM2/28/16
to Django users
Igor,

Yes, the server was started.  Here are the contents of the command window including after trying to go to the website.


C:\Data\Django_Code\FirstApp\mysite>python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
February 28, 2016 - 21:05:58
Django version 1.9.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /polls/
[28/Feb/2016 21:06:30] "GET /polls/ HTTP/1.1" 404 1921
Not Found: /favicon.ico
[28/Feb/2016 21:06:31] "GET /favicon.ico HTTP/1.1" 404 1936

jorr...@gmail.com

unread,
Feb 29, 2016, 8:40:43 AM2/29/16
to Django users
Did you add 'polls' to your list of INSTALLED_APPS in your settings.py? After that you should run > python manage.py migrate like the terminal is suggesting to you.

Mike Kipling

unread,
Feb 29, 2016, 10:03:42 AM2/29/16
to Django users
Jorr,

No, I did not modify the settings.py file, because the tutorial specifically states: 

Note

Ignore the warning about unapplied database migrations for now; we’ll deal with the database shortly.


Here is a link to the tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial01/





jorr...@gmail.com

unread,
Feb 29, 2016, 3:02:03 PM2/29/16
to Django users
Well that's strange... The problem appears to be that your polls.urls file is not getting included in your project's URLConf (since the error message in your first post says that the only URL tried was admin/ ). I'm not sure if adding the app to INSTALLED_APPS is necessary for an app's URLConf to be able to be included, but it's worth a try. In FirstApp/settings.py add 'polls' to the list of INSTALLED_APPS so that it looks something like this:

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



Otherwise it does seem like it could be a file refresh problem.

Mike Kipling

unread,
Feb 29, 2016, 3:23:20 PM2/29/16
to Django users
I added polls to settings.py :
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls.apps.PollsConfig',
]

Then I tried the migration:
C:\Data\Django_Code\FirstApp\mysite>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, sessions, contenttypes, auth
Running migrations:
  No migrations to apply.

Then I started the server and tried going to the address, but got the same results:
C:\Data\Django_Code\FirstApp\mysite>python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
February 29, 2016 - 14:16:37
Django version 1.9.2, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /polls/
[29/Feb/2016 14:16:46] "GET /polls/ HTTP/1.1" 404 1921

I am working on a Windows OS, so I thought that perhaps changing the '/' in the mysite\urls.py to '\\' might help, but it did not.

jorr...@gmail.com

unread,
Feb 29, 2016, 3:48:44 PM2/29/16
to Django users
Can you attach your entire project's code in a ZIP file? I'm curious to test this myself...

Mike Kipling

unread,
Feb 29, 2016, 4:10:58 PM2/29/16
to Django users
I found the problem.

When the mysite\urls.py file is created, it has this line already in it.

from django.conf.urls import url

The tutorial asks you to add the following lines to the 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),
]

I must did not notice that the 'include' was different, and so I had not placed it into the file.  I changed the file to add the 'include' and everything worked.

Thank you for the help.

jorr...@gmail.com

unread,
Mar 2, 2016, 3:19:16 PM3/2/16
to Django users
Glad you got it solved!!

Ruth

unread,
Mar 17, 2016, 4:07:11 PM3/17/16
to Django users
Hi,
I am getting the same problem, despite having include in my mysite\urls.py file.
I am using Python 2.7.6, Django 1.9.4 and Ubuntu 14.04.3 LTS.
Could it by a Python 2.7 problem?
Thanks,
Ruth

Ruth

unread,
Mar 17, 2016, 4:07:11 PM3/17/16
to Django users
I am getting the very same problem, despite adding include to my mysite\urls.py file.

I am using Python 2.7.6, Django 1.9.4 and Ubuntu 14.04.3 LTS
Could it be a python 2.7 problem?
Thanks,
Ruth

Bruno Barbosa

unread,
Mar 17, 2016, 4:56:04 PM3/17/16
to django...@googlegroups.com
Ruth,

Show me the code!

How is your urls.py? and the views.py?

paste your code in https://gist.github.com/ and reply this email.

--
Bruno Barbosa
Web Developer

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c14e04f8-be34-4569-ae42-48e8d4135a2c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

David Bon

unread,
Jun 19, 2016, 12:15:58 PM6/19/16
to Django users
I was having the exact same problem.

In fact I was not modiying the right urls.py

On windows dirs i've got:
mysite/
     urls.py


In fact there the in your

Vanja Falck

unread,
Mar 7, 2017, 6:55:47 AM3/7/17
to Django users
Hi,
I am also facing the same problems with the djangoproject tutorial - I have changed the settings.py file to add the polls app, but it did not solve the issue:
When runserver: I get the admin page, but not the polls page. Get a similar 404 error page as Kipling, but with the ˆpolls/ url in the list.

Running in virtualenv - with python 3.5.2 and django 10.1.6 on Ubuntu 16.04. Any idea of what is wrong?

Here is my code:

# Your first view: opprettet polls/urls.py

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'ˆ$', views.index, name='index'),
]

# Your first view polls/views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("Hoppla, polls index her..")

# Site/urls.py

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),
]
# Site/settings.py
# Application definition

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

Melvyn Sopacua

unread,
Mar 8, 2017, 3:52:24 AM3/8/17
to django...@googlegroups.com

Hi,

 

On Tuesday 07 March 2017 01:24:02 Vanja Falck wrote:

 

 

> urlpatterns = [

> url(r'ˆpolls/', include('polls.urls')),

> url(r'^admin/', admin.site.urls),

> ]

 

Easy to see this way. You didn't type a caret but some unicode sign that looks like a caret.

--

Melvyn Sopacua

Daniel Bess

unread,
Mar 8, 2017, 11:16:20 AM3/8/17
to django...@googlegroups.com
Hello!

Daniel

-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Thomas Pittman

unread,
Mar 15, 2017, 5:58:44 PM3/15/17
to Django users


Here is the error I keep getting. I've started this tutorial on python 3.6. I ran into the problems people had before. Somehow I've fixed them before I got here. I can't seem to reconcile this part. Any suggestions?
Auto Generated Inline Image 1

Thomas Pittman

unread,
Mar 15, 2017, 5:59:24 PM3/15/17
to Django users
from django.conf.urls import url
from django.conf.urls import include
from django.conf.urls import polls\

from django.contrib import admin

urlpatterns = [
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include('admin.site.urls')),
]

Here is a copy of the the mysite.py file. I'm not sure how, but the error stopped after I imported imclude and polls this way.

Camilo Torres

unread,
Mar 16, 2017, 11:43:36 AM3/16/17
to Django users
Hi.

You may have a strange, non-visible character in your file just before the line giving error.

Vijay Khemlani

unread,
Mar 16, 2017, 11:45:58 AM3/16/17
to django...@googlegroups.com
Why is there a backslash in

from django.conf.urls import polls\

?
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f9e098eb-2362-4cc1-bc41-0b5a03f64172%40googlegroups.com.

Thomas Pittman

unread,
Mar 16, 2017, 11:52:12 AM3/16/17
to django...@googlegroups.com
I'm not sure why, but it stopped the error and send to import it. I'm using 3.6?

On Mar 16, 2017 11:45 AM, "Vijay Khemlani" <vkhe...@gmail.com> wrote:
Why is there a backslash in

from django.conf.urls import polls\

?

On 3/16/17, Camilo Torres <camilo...@gmail.com> wrote:
> Hi.
>
> You may have a strange, non-visible character in your file just before the
> line giving error.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f9e098eb-2362-4cc1-bc41-0b5a03f64172%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/aZQoPBeHDPs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Kamal Kumar Bharadwaj

unread,
May 4, 2018, 5:48:52 PM5/4/18
to Django users
Hi Guys,

I am facing trouble while running the tutorial for Django. I have attached the error details and the complete code. I am using python 3.x, django 2.0.x with anaconda distribution on python. Please help me asap.


Thanks in advance!


Regards,

Kamal Kumar Bharadwaj



On Thursday, 16 March 2017 21:22:12 UTC+5:30, Thomas Pittman wrote:
I'm not sure why, but it stopped the error and send to import it. I'm using 3.6?
On Mar 16, 2017 11:45 AM, "Vijay Khemlani" <vkhe...@gmail.com> wrote:
Why is there a backslash in

from django.conf.urls import polls\

?

On 3/16/17, Camilo Torres <camilo...@gmail.com> wrote:
> Hi.
>
> You may have a strange, non-visible character in your file just before the
> line giving error.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f9e098eb-2362-4cc1-bc41-0b5a03f64172%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/aZQoPBeHDPs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
ErrorDetails.PNG
website.zip

Elorm Koku

unread,
May 4, 2018, 6:07:53 PM5/4/18
to django...@googlegroups.com
You don't have anything like music/index in your urls.py file ....yet you are putting it in your request. 

Mayank Bhatia

unread,
Jun 16, 2018, 9:39:07 AM6/16/18
to Django users
hello guys,

I am facing the same error while creating the views.

Asong nkemzi

unread,
Sep 20, 2018, 2:48:31 PM9/20/18
to Django users
Hello, Ruth did you ever solve this problem? I am experiencing exactly the same issue

Joel

unread,
Sep 20, 2018, 9:49:47 PM9/20/18
to django...@googlegroups.com
Show the urls.py after adding everything. Note that there must be two urls.py. One in the project folder, another in the app folder

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

John Meyer

unread,
Sep 21, 2018, 7:43:47 AM9/21/18
to Django users
I have been testing this tutorial frequently over the last few days (with success) and am using an empty string ( ‘’ ) for the route (first argument to path) in the app’s urls.py, rather than the ‘raw’ string value I see in the earlier posts here.

Asong nkemzi

unread,
Sep 21, 2018, 10:28:18 AM9/21/18
to django...@googlegroups.com
I figured it out thanks Guys! like every one else I just added my app string to the application VARIABLE in mysite/settings.py  works fabulously

On Fri, Sep 21, 2018 at 7:43 AM John Meyer <john....@app-project.com> wrote:
I have been testing this tutorial frequently over the last few days  (with success) and am using an empty string ( ‘’ ) for the route (first argument to path) in the app’s urls.py, rather than the ‘raw’ string value I see in the earlier posts here.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Nitin Tiwari

unread,
Jan 4, 2019, 7:38:47 AM1/4/19
to Django users
I just wanna, explain my experience, in the official tutorial https://docs.djangoproject.com/en/2.1/intro/tutorial01/  when they tell you to edit urls file of mysite directorythey didnt mention which one. And in the beginning of tutorial our project name is also mysite, so i thought that I have to create new urls.py out side. but you have to to use inbuilld one. 
Message has been deleted

kyle D

unread,
Mar 24, 2020, 10:46:16 PM3/24/20
to Django users
I'm using Django for a class, and came across this thread and thought I'd post what fixed it for me in case someone else has the same issue I did.

Makes sure your mysite/urls.py is the one that has the urlpatterns[] with the path to your polls and not the mysite/polls/urls.py.

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

 
Not this one:
app_name = 'polls'
urlpatterns = [
    # ex: /polls/
    path('', views.index, name='index'),

Thomas Pittman

unread,
Mar 25, 2020, 4:21:35 PM3/25/20
to django...@googlegroups.com
Kyle D,

This is why I stay in this thread. Thanks for the heads up. I remember being so lost when I tried to start teaching myself Django. What's the class for?

Regards


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/aZQoPBeHDPs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/61ca2cd8-70cb-4a5b-8ae7-5657ef413209%40googlegroups.com.

temitope iyanoye

unread,
Jun 12, 2020, 8:22:52 AM6/12/20
to Django users
I’m using Django 3.0 and I have this same issue following the official Django tutorial, has anyone been able to fix it? Please I need help, thanks

Lithium

unread,
Jul 20, 2020, 4:32:27 PM7/20/20
to Django users
In in mysite/urls.py
check the "/" after "polls" in this line:
path('polls/', include('polls.urls'))


Reply all
Reply to author
Forward
0 new messages