Santosh Kantharaj
Santosh Kantharaj

Reputation: 161

Django First Tutorial: ImportError: No module named 'polls'

I've set up Django on my Windows 10 PC, and was working through the first tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial01/

I can't seem to do the first part, because of an import error.

Here's the views.py script:

mysite/polls/views.py

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.") 

urls.py in the polls app:

mysite/polls/urls.py

from django.conf.urls import url
import views

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

And urls.py in mysite:

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

After troubleshooting and fixing issues with the first two files, this is the error I get when I run "python urls.py" on the mysite urls.py file:

enter image description here

I've seen a few stackoverflow posts here regarding this tutorial, and similar issues. Someone advocated that I add polls to the INSTALLED_APPS section of settings.py, but this did not work.

/mysite/mysite/settings.py

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

I also read that someone got this to work by adding the 'polls' module to their pythonpath... But I'm not sure if this is the way to go.

A very similar post was made here: Django reusable apps tutorial, ImportError: No module named 'polls' but no solution was provided.

Anyone with some insight or input, please let me know what I can do to fix this, and let me know if you need any more information.

Upvotes: 0

Views: 1309

Answers (1)

coder7891
coder7891

Reputation: 151

You seem to be running urls.py. shouldn't you be running python manage.py runserver command to start the app. Are you trying to achieve something else here ?

Upvotes: 1

Related Questions