Home > Enterprise >  ModuleNotFoundError: No module named 'app.project'
ModuleNotFoundError: No module named 'app.project'

Time:01-26

Mb I am idiot but I wanna know what I do wrong

i think my problem is here

setting.py

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

or here

urls.py

    from django.contrib import admin
    from django.urls import path
    from app.project import views

    urlpatterns = [
        path('', views.index, admin.site.urls),
        path('admin/', admin.site.urls),
    ]

error and packages

CodePudding user response:

If you start Django from the first app directory via python ./manage.py runserver, then the app is your base directory, you don't have to append app to your module called project.

The corrected settings:

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

URLs:

from django.contrib import admin
from django.urls import path
from project import views

urlpatterns = [
    path('', views.index, admin.site.urls),
    path('admin/', admin.site.urls),
]

CodePudding user response:

Just in case someone has moved their app into another folder such as an apps folder (which I typically do), you'd have to use apps.your_app_name in the installed apps and then in your apps.py file, change the name to apps.your_app_name.

  •  Tags:  
  • Related