module not found when using include in django
Question:
I’m trying to use include in my app following the tutorial here – https://www.w3schools.com/django/django_views.php
it seems that when I run the server using this configuration-
urlpatterns = [path('members/', include('mimi.urls')), path('admin/', admin.site.urls),]
I get ModuleNotFoundError: No module named ‘mimi’.
I’ve attached a screenshot of my Pycharm project folder as it is now.
I don’t understand what I’m doing wrong. It seems to fail to recognize anything outside the web_questions folder, but I can’t find a way to give it the absolute path.
I’m running the server using this command line –
py web_questions/manage.py runserver
Answers:
please check wheather your module "mimi" is present in the INSTALLED_APPS List in the settings.py file. If not u can add it in INSTALLED_APPS List.
So like people have said here before ,the app directory should be under the project directory!
The way to do it easily, and without transferring manually the folders, is to run this line of code-
django-admin startproject <project_name>
cd .<project_name>
python .manage.py startapp <app_name>
The second line is what made all the difference for me, and I didn’t see it in the tutorial.
This way everything is created in the correct hierarchy.
I’m trying to use include in my app following the tutorial here – https://www.w3schools.com/django/django_views.php
it seems that when I run the server using this configuration-
urlpatterns = [path('members/', include('mimi.urls')), path('admin/', admin.site.urls),]
I get ModuleNotFoundError: No module named ‘mimi’.
I’ve attached a screenshot of my Pycharm project folder as it is now.
I don’t understand what I’m doing wrong. It seems to fail to recognize anything outside the web_questions folder, but I can’t find a way to give it the absolute path.
I’m running the server using this command line –
py web_questions/manage.py runserver
please check wheather your module "mimi" is present in the INSTALLED_APPS List in the settings.py file. If not u can add it in INSTALLED_APPS List.
So like people have said here before ,the app directory should be under the project directory!
The way to do it easily, and without transferring manually the folders, is to run this line of code-
django-admin startproject <project_name>
cd .<project_name>
python .manage.py startapp <app_name>
The second line is what made all the difference for me, and I didn’t see it in the tutorial.
This way everything is created in the correct hierarchy.