Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to start up a very basic web app with Django and getting
ModuleNotFoundError: No module named 'ui'
My django project is
frontend_project
and the app is
ui
Tree:
front_end
├── front-end/Pipfile
├── front-end/Pipfile.lock
├── front-end/README.md
├── front-end/db.sqlite3
├── front-end/frontend_project
│ ├── front-end/frontend_project/__init__.py
│ ├── front-end/frontend_project/
│ │ └──front-end/frontend_project/ui
│ │ ├── front-end/frontend_project/ui/__init__.py
│ │ ├── front-end/frontend_project/ui/admin.py
│ │ ├── front-end/frontend_project/ui/apps.py
│ │ ├── front-end/frontend_project/ui/migrations
│ │ │ └── front-end/frontend_project/ui/migrations/__init__.py
│ │ ├── front-end/frontend_project/ui/models.py
│ │ ├── front-end/frontend_project/ui/tests.py
│ │ ├── front-end/frontend_project/ui/urls.py
│ │ └── front-end/frontend_project/ui/views.py
│ ├── front-end/frontend_project/settings.py
│ ├── front-end/frontend_project/urls.py
│ └── front-end/frontend_project/wsgi.py
└── front-end/manage.py
Installed_apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ui.apps.UiConfig',
And my frontend_project
urls.py looks like:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('ui.urls')),
ui
urls.py
from django.urls import path
from .views import homePageView
urlpatterns = [
path('', homePageView, name='home'),
EDIT: I removed the apps directory and placed the UI app under the project directory - Still experiencing the same error ModuleNotFoundError: No module named 'ui'
I'm just trying to get a simple web app working for right now and my python version is 3.6.7 and pipenv.
Thanks all!
–
–
You have configured your project in an atypical way. While not absolutely required, the most straightforward (and most common) way to structure the project is to include your project apps in the root directory, which is the directory that contains manage.py.
In your case, your 'ui' app directory would be located at front_end/front_end/. (Not under /front_end/front_end/front_end/frontend_project/)
IF you want to keep the project structure that you currently have, there are a additional configuration changes necessary, including subclassing AppConfig (see below).
You will also need to use a dotted path to your application urlconf from your root UrlConf (This is the configuration step that you missed that is likely causing the error).
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('frontend_project.ui.urls')), <--- here
In your case, by defining a direct path to 'ui.apps.UiConfig'
in INSTALLED_APPS, Django looks for the configuration in the dotted path to the AppConfig subclass for that application which is located in apps.py.
# ui/apps.py
from django.apps import AppConfig
class UiConfig(AppConfig):
name = 'ui'
–
–
–
–
Import urls.py file of Ui app in frontend_project urls.py file.
from django.contrib import admin
from django.urls import path, include
from ui import urls
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('ui.urls')),
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.