Include apps.urls error

Hey

I am following a basic tutorial, and I am literally stuck there:

In urls.py 's project file:

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

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

In urls.py 's “back” app file:

from django.urls import path
from .views import AccountView

urlpatterns = [
    path('account', AccountView.as_view()),
]

and in INSTALLED APPS:

INSTALLED_APPS = [
    ...
    'rest_framework',
    'back',
]

I keep on getting this error:

path('/', include("back.urls"))
              ^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'back'

Can anyone advise me what I am missing please?

I am using Python 3.12 and Django 5.1.1.

Welcome @lopman045 !

Please show your directory structure.

Identify the complete paths where your project urls.py and your back app’s urls.py files are located.

Thank you very much!

My project structure is as follow;

It’s quite hard to read that with so little indent. Is manage.py inside back?

Apologies for that. Let me rewrite the structure there:

´´´
backend
|__ back
—-|__ urls.py
. …
|__ omg_back
—-|__ omg_back
———|__ urls.py
———|__ setting.py
. …
—-|__ manage.py

This structure seems wrong to me. manage.py should be on the top level. So I guess that would be inside backend. Then THAT should be the current working directory when running manage.py. Alternatively you move back into the outermost omb_back dir. I think it’s very confusing that you have 4 folders called variations on “backend”. One seems reasonable, 4 is too much :stuck_out_tongue:

what is your project name and result of print(base_dir) in settings.py?

I see. Initially the ´back´ app was named ´api ´, but I thought the name could the reason of the error.

The project name is ´omg_back´

your project not include app named back.

you should :

|__ omg_back
—-|__ omg_back
———|__ urls.py
———|__ setting.py
———|__ back
. …
—-|__ manage.py

Unless you have a real need to not follow the Django conventions, I would strongly suggest you organize your project as described at Is the structure of the project correct? - #2 by KenWhitesell

While there are other valid ways to organize your project, you will create less friction by doing it this way.