Django Tutorial. No module named '__main__.models'

Currently on page 3 of Python Django tutorial (Views and Templates)
The error has come up here:

from .models import Question

* > def index(request):
* >     latest_question_list = Question.objects.order_by('-pub_date')[:5]
* >     template = loader.get_template('polls/index.html')
* >     context = {
* >         'latest_question_list': latest_question_list,
* >     }
* >    return HttpResponse(template.render(context, request))

The full error message comes up as: 'No module named ‘main.models’; ‘main’ is not a package. I’m not sure how to fix this, I’ve tried removing the ‘.’

Hi - I think you’re trying to execute your views file directly with e.g. python polls/views.py. This makes it the __main__ module in Python, rather than polls.views. It should work if you stick to python manage.py runserver etc.

1 Like

Oh, I would just run it to save the code I’ve written and check for any errors. Thanks ever so much, I’ve managed to get everything running properly now.