0
votes

I am following a tutorial online for a to-do app using Django, but I keep getting this error.

File “C:\DjangoStuff\my_app\todo_app\urls.py”, line 3, in from todo_list import views File “C:\DjangoStuff\my_app\todo_list\views.py”, line 3, in from .forms import ListForm ModuleNotFoundError: No module named ‘todo_list.forms’

I have tried deleting and adding back the forms.py file, but no success. The todo_list folder does contain all the files being referenced as far as I can tell.

I have a todo_list folder where all the below mentioned files are stored

This is the code I have imported in the urls.py file:

from django.urls import path
from . import views

in the views.py file, I have the following imported:

from django.shortcuts import render, redirect
from .models import List
from .forms import ListForm
from django.contrib import messages
from django.http import HttpResponseRedirect

I have also created the models.py file and forms.py files as part of the todo_list folder.

I'ms sure it's something simple but have been through the tutorial many times and cannot find anything wrong...

File list

1
Have you tried restarting the server after adding it back?nishit chittora
Please show your folder structure with mentioned files.Ivan Starostin
@nishitchittora Yes I have. I will try to restart my PC and see if it works. I haven't had such a problem before when I tried to build the same app.Werner
@IvanStarostin Thanks. I have uploaded an image under the link 'File List'. You'll see that it contains all the files under the todo_list folder.Werner
Please tend to post info in text, not in pictures. Your forms.py is in wrong place. Move it one level up - to the folder where views.py lies.Ivan Starostin

1 Answers

0
votes

Your forms.py file should be in the folder todo_list\, not under todo_list\templates\ as it is now.

from .forms import ListForm in the views.py file expect to find the forms.py file in the same directory (.)

Other solution could be to let the file where it is now, but state instead in the views.py file from todo_list.templates.forms import ListForm