hkhr hkhr - 1 year ago 185
Python Question

"ImportError: No module named urls" while following Django Tutorial

I am following the official django tutorial

I am using Django 1.9.8 and I am now getting the following error in


File "C:\Users\hk\Documents\mysite\polls\", line 4, in <module>
from django.urls import reverse
ImportError: No module named urls


from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse

from .models import Choice, Question
# ...


from django.conf.urls import include, url
from django.contrib import admin


url(r'^polls/', include('polls.urls')),


from django.conf.urls import include,url
from django.contrib import admin

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

Answer Source

That tutorial requires Django 1.10 while you seem to be using an older version. In this case, you should import reverse as follows:

from django.core.urlresolvers import reverse

To upgrade your Django version, use the following command (in your command line, not in the Python shell):

pip install --upgrade django