ModuleNotFoundError

Hi all,

I have setup a django project but unfortunately I have a ModuleNotFoundError after I changed project folders…

The following error pops up:
File “C:\Users\Lenovo\AppData\Local\Programs\Python\Python38-32\lib\importlib_init_.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 961, in _find_and_load_unlocked
File “”, line 219, in _call_with_frames_removed
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'digital_portfolio’

This is what I have in my project (unfortunately I could only upload one image… ):
folder structure,

Maybe in addition to the ModuleNotFoundError, my “polls” folder say: “Contatins emphasized items”.

Hopefully the topic is clear, please let me know if any additional information is needed.

apps.py

models.py

Instead of trying to upload images, please post code and directory listings as text, between lines consisting only of three backtick ` characters. So you would have a line of ```, then lines of code, then one more line of ```. (Note, be sure you use the backtick ` and not the apostrophe '.)

Briefly, something is trying to import code from a module named digital_portfolio, but I don’t see any module directory by that name in the listing you included. (You should have one by that name at the same level as “mysite” and “polls”.)

Hi Ken,

I am sorry for the post.

If I understand you correct, when I change the polls folder to digital_portfolio folder, the issue should be fixed?

I don’t know. We would need to see your settings.py file and your urls.py file to be sure, but changing the name of “polls” to “digital_portfolio” should help with the specific issue you identified. (It may not be the only change needing to be made, however.)

Ken

Thanks for the response Ken,

The code inside the setting.py file below:

    'digital_portfolio',
    
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'digital_portfolio.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'digital_portfolio.wsgi.application'

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR

The code inside the urls.py file:

from django.contrib import admin
from django.urls import path
import digital_portfolio.views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ADMIN PAGE!
    path('admin/', admin.site.urls),
    # HOMEPAGE! 
    path('', views.index, name='index'),

    # PROFESSIONAL WORK EXPERIENCE PAGE!
    path('professional-work-experiences', digital_portfolio.views.home, name='home'),
    path('jobs-details/<int:job_id>', digital_portfolio.views.detail, name='detail'),
] 
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Could you maybe explain why you need to see this particular files? As a beginner it is hard to understand the actual meaning of the “polls” folerder and the “templates” folder. I got this information from the official django website.

Like to hear :slightly_smiling_face:

Sure.

settings.py - I specifically wanted to see the INSTALLED_APPS setting - which you show the digital_portfolio app, and what follows it, but not what comes before. I wanted to know if there was anything related to that setting that might need to be addressed.

I also wanted to see your ROOT_URLCONF setting to verify that it’s pointing to the digital_portfolio app.

In your urls.py, I wanted to verify that you’re referencing a digital_portfolio app and nothing else.

So it was mostly to see if there was any other changes I might need to suggest.

The “polls” folder is a django “app”. That directory name must match what’s in your INSTALLED_APPS setting. If you defined an app named digital_portfolio, then that means you must have a directory by that name.
The templates/digital_portfolio directory is the standard location for storing templates for an app by that name. Two directories with different (but coordinated) purposes.

Ken

Thanks, I really appreciate the explanation.

So I have changed the “polls” folder to digital_portfolio. But instead I have the following error:

ModuleNotFoundError: No module named 'digital_portfolio.settings’

Should I add in the “urls.py” file (see below) a code, import digital_portfolio.settings?

from django.contrib import admin
from django.urls import path
import digital_portfolio.views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ADMIN PAGE!
    path('admin/', admin.site.urls),
    # HOMEPAGE! 
    path('', views.index, name='index'),

    # PROFESSIONAL WORK EXPERIENCE PAGE!
    path('professional-work-experiences', digital_portfolio.views.home, name='home'),
    path('jobs-details/<int:job_id>', digital_portfolio.views.detail, name='detail'),
] 
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Just as a side note, I’m guessing you’re finding yourself in this situation because you did the tutorial and are trying to rename things for your own project?

I’d suggest in the future that you start projects from scratch. If you followed the tutorial exactly, you started with a manage.py startproject myapp followed by a manage.py startapp polls. You could follow the same pattern, but instead of “polls”, you do manage.py startapp digital_portfolio and rebuild your project from there.

Off the top of my head, I can’t think of everything you might need to do to clean this all up. You might be able to chase this down item by item - or you might not.

I’d recommend starting clean with a new project here.

Ken

Hi Ken,

Yes I followed the tutorial as I am a beginner :sweat_smile:.

I have started I new project, probably a good learning process by making a new project :+1:.
I think I will be quit often active on this forum in future haha.