ModuleNotFoundError: No module named 'calc.urls' (calc is the name of my app)

I am new in django
I have already installed the module(calc) but i am still getting the error .I have been struggling with this for the last 3 days.Any help please

Application definition


from django.urls import path

from . import views

urlpatterns =[
path(‘’,views.home, name=‘home’)

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

Create your views here.

def home(request):
return HttpResponse(“Hello World”)

Do you have a file named within your calc directory? What does your directory structure look like?
(It probably should look something like this:

... and any other directories as needed.)

What is the exact and complete error you’re getting?
When and where are you getting it?

I noticed in one of your other posts that you might be getting this as an error in your IDE? If so, you can safely ignore it. (How you would resolve it depends upon what IDE you’re using and potentially some configuration issues for it.)

Hello sir, i’m just starting to learn django and I found the same problem as the thread owner, probably he followed the same tutorial as me in #4 Django tutorials | First App Django - part 2 - YouTube because the code he stated is the same as in the video

I already take all the steps in the video but i have got an error (No module named ‘calc’) in the python terminal. I search hours for solution such as using absolute and relative import for calc.urls but still get an error (attempted relative import with no known parent package)

The other thing is I cannot use [from . import views] in the calc.urls file but instead i use [import views] and it does’nt occur an (attempted relative import with no known parent package) error

Can you give me some solution for this? or maybe i have some configuration that is still not enabled? I’m using python 3.10.4 and enable virtual environment for the code

You’re going to need to provide more specific and detailed information about the issue you’re encountering.

This includes showing your directory structure, your settings, and the file which is creating this error. Also identify what version of Django you are using, what operating system you’re running this on, and the command you are running that is generating this error.

This will get us started. There may be more questions based upon your response to these.

Note: When posting code, error messages, templates, etc here, copy/paste the code in to the body of your post, surrounded by lines of three backtick - ` characters. This means you’ll have a line of ```, then your code (or error message, or template, etc), then another line of ```. Please do not post images of code or other terminal output.

1 Like

Thanks for the reply, my django version is 4.0.6 and i’m on windows 10

This is my directory structure:

Code for calc/

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

def home(request):
    return HttpResponse("Hello World1")

This code works well in the python terminal

Code for calc/

from django.urls import path

from . import views

urlpatterns = [
    path('',views.home, name='home')

from . import views, command got an error ImportError: attempted relative import with no known parent package in the python terminal

Code for LearnDjango1/

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

urlpatterns = [
    path('', include('calc.urls')),

The path('', include('calc.urls')), command got an error ModuleNotFoundError: No module named 'calc' in the python terminal

After i try to execute python runserver command in the cmd, it seems i can display “Hello World1” in my server address and works well but i still confused why i get the error in the python terminal

The issue is that the Python terminal is not running the Django environment. It’s not valid to use it for that. That’s why Django provides the shell command.

Also see: Writing your first Django app, part 2 | Django documentation | Django