Forums

ViewDoesNotExist

I'm working through the Django tutorial.

I've added 'mysite.polls' to Settings.INSTALLED_APPS

I've added

'url(r'^polls/$', 'polls.views.index'),
url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),'

to mysite.urls.urlpatterns

I've added:

'from django.http import HttpResponse

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

to mysite.polls.views.py

I reload the site, and go to http://bjornagain.pythonanywhere.com/polls/ and get the ViewDoesNotExist error, 'Exception Value:
Could not import polls.views. Error was: No module named polls.views'

What am I missing?

There are a few things that can be wrong when people follow the Django tutorial:

  1. They are using a different version of Django - check that you're going through the right tutorial for the version you're using.
  2. Sometimes the Python path between a PythonAnywhere web app and the tutorial are slightly different. Try importing mysite.polls.views instead of polls.views to see if that's the case.

Thanks glenn. I changed

'url(r'^polls/$', 'polls.views.index'),'

in urls.py to:

'url(r'^polls/$', 'mysite.polls.views.index'),'

and it worked.

It works for me to. Thank you for the answer!