3

I am following the official Django tutorial on https://docs.djangoproject.com/en/2.2/intro/tutorial01/ but somehow I am not able to run the server as I have created the polls app and added the required urls. When I use the command "py mysite\manage.py runserver" it returns me ModuleNotFoundError: No module named 'polls' error.

Project Folder available at https://i.stack.imgur.com/bbxfW.png

#views.py

from django.http import HttpResponse


def index(request):
    return HttpResponse('<h1><this is a test page</h1>')
#urls.py in polls

from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]
#urls.py in mysite\mysite

from django.contrib import admin
from django.urls import include, path

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

#settings.py

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


  [1]: https://i.stack.imgur.com/bbxfW.png
BlockeeR
  • 221
  • 1
  • 4
  • 16

2 Answers2

6

Well, I resolved it myself. Polls module was not found because it was created outside the project directory. When I removed it and recreated inside the project directory, it was OK now.

BlockeeR
  • 221
  • 1
  • 4
  • 16
1

also it may be a good idea to cd into yoru django project so you are only running

python manage.py runserver
HamishLacmane
  • 88
  • 1
  • 11