ModuleNotFoundError: No module named 'main.utilities' - but it exists

Hi. I have just started building my first django app and am currently stuck at the part where I’m supposed to be executing a python manage.py makemigrations

Upon executing the ‘python manage.py makemigrations’ command in the terminal, I received this error:

(venv) PS C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard> Python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\apps\config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard\main\models.py", line 5, in <module>
    from .utilities import send_activation_notification
ModuleNotFoundError: No module named 'main.utilities'

This is my settings.py file.

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-7n1pyfqd2&#)3%=2-2@hqpqpak#itpw4mlp5&*+gk3xb6okda%'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main.apps.MainConfig',
    'bootstrap4',
]
AUTH_USER_MODEL = 'main.AdvUser'

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 = 'bboard.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 = 'bboard.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'bboard.data',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'ru-r'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'username@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

This is my apps.py file:

from django.apps import AppConfig


class MainConfig(AppConfig):
    verbose_name = 'Электронная доска объявлений'
    name = 'main'

This is my models.py file:


from django.db import models
from django.contrib.auth.models import AbstractUser
from django.dispatch import Signal
from .utilities import send_activation_notification

class AdvUser(AbstractUser):
    is_activated = models.BooleanField(default=True, db_index=True,
            verbose_name='Прошел активацию?')
    send_messages = models.BooleanField(default=True,
            verbose_name='Оповещать при новых комментариях?')
class Meta(AbstractUser.Meta):
    pass

user_registrated = Signal(providing_args=['instance'])

def user_registrated_dispatcher(sender, **kwargs):
    send_activation_notification(kwargs['instance'])


user_registrated.connect(user_registrated_dispatcher)
class AdvUser(AbstractUser):
    is_activated = models.BooleanField(default=True, db_index=True,
                                       verbose_name='Прошел активацию?')
send_messages = models.BooleanField(default=True,
                                    verbose_name='Оповещать при новых комментариях?')

class Meta(AbstractUser.Meta):
    pass

class Rubric(models.Model):
    name = models.CharField(max_length=20, db_index=True, unique=True,
                            verbose_name='Название')
order = models.SmallIntegerField(default=0, db_index=True,
                                 verbose_name='Порядок')
super_rubric = models.ForeignKey('SuperRubric',
                                 on_delete=models.PROTECT, null=True, blank=True,
                                 verbose_name='Надрубрика')

class SuperRubricManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(super_rubric__isnull=True)


class SuperRubric(Rubric):
    object = SuperRubricManager()

def __str__(self):
    return self.name
class Meta:
    proxy = True
    ordering = ('order', 'name')
    verbose_name = 'Надрубрика'
    verbose_name_plural = 'Надрубрики'

class SubRubricManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(super_rubric__isnull=False)


class SubRubric(Rubric):
    object = SubRubricManager()

def __str__(self):
    return '%s - %s' % (self.super_rubric, self.name)
class Meta:
    proxy = True
    ordering = ('super_rubric__order', 'super_rubric__name', 'order', 'name')
    verbose_name = 'Подрубрика'
    verbose_name_plural = 'Подрубрики'

Django version - 3.2.16
Python version - 3.7.2
Pip version - 21.3.1

I have also included a screenshot of my settings.py file in case there is some info I forgot to mention. The entire directory is visible in the image.
I suspect the problem may be due to the placement of my file directories. Any advice?

What is this utilities that is trying to be referenced?

Also, what does your main.apps.MainConfig look like?

“utilities” is the file I created from the materials. here is what it says:
“Tools for sending activation emails”
In order for the registration to work, we need to write a code that will execute
sending emails notifying you of the need to activate.
Direct mailing of letters will be performed by the function
send_activation_notification(), which we will declare later, in the newly created module
utilities.py"

main.apps.MainConfig is it in settings.py or is it a separate file?
I’ll attach the entire settings.py code:

"""
Django settings for bboard project.

Generated by 'django-admin startproject' using Django 3.2.16.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-7n1pyfqd2&#)3%=2-2@hqpqpak#itpw4mlp5&*+gk3xb6okda%'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main.apps.MainConfig',
    'bootstrap4',
]

AUTH_USER_MODEL = 'main.AdvUser'

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 = 'bboard.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 = 'bboard.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'bboard.data',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'ru-r'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'username@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

Thank you very much for your answer!

Ok, I just noticed that you have the utilities.py file in your templates directory. It should be in the parent directory named main. (At the module level and not within the templates directory.)

In the main directory, there should be a file named apps.py. MainConfig should be in that file.

Thank you! you are right,The file was indeed in the wrong place, but strangely today I already found this error and fixed it, but apparently I did not save the project correctly and there was nothing left. I did everything right, but it still shows this error:

(venv) PS C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard> Python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\apps\config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard\main\models.py", line 5, in <module>
    from .utilities import send_activation_notification
ModuleNotFoundError: No module named 'main.utilities'

And also I found the file apps.py and this is what is there:

from django.apps import AppConfig


class MainConfig(AppConfig):
    verbose_name = 'Электронная доска объявлений'
    name = 'main'

Side note: please stop posting screen images of your directory structure - they’re really hard to read. If you think that posting a full directory listing is appropriate, copy/paste the output of either ls -R or a tree command in Linux (or Mac) or a dir /s /w in Windows.

The next thing to check will be the utilities.py file itself. An error within that file could prevent it from being imported.

Okay, I got you!
I’ll take a look at this file
Please tell me how to save the project in PyCharm so that I can open it on another computer. Before that, I pressed Ctrl + S, but why the project is not saved.

Sorry, I can’t help you there. I don’t use PyCharm. Normally, when I need to work on a project between computers, I check the project into a git repo (we use gitlab), and then pull the project on the second computer.

Okay. Do you know why the project path has changed? When I asked the question the path was slightly different.
Right now I see this path (venv) PS C:\Users\Alex\AppData\Local\Temp\Rar$DRa0.292\pythonProjectTown>

what is Rar$DRa0.29 ? and where is it from?

That’s outside the context of your project - that wouldn’t be anything that Django is doing. I wouldn’t have any way of knowing what is creating your directory structure. (Since it is outside the Django project, it shouldn’t be affecting any code within your project.)

1 Like

Utilities.py:

from django.template.loader import render_to_string
from django.core.signing import Signer

from bboard.settings import ALLOWED_HOSTS

signer = Signer()



def send_activation_notification(user):
    if ALLOWED_HOSTS:
        host = 'http://' + ALLOWED_HOSTS[0]
    else:
            host = 'http://localhost:8000'
            context = {'user': user, 'host': host, 'sign': signer.sign(user.username)}
            subject = render_to_string('email/activation_letter_subject.txt',
            context)
            body_text = render_to_string('email/activation_letter_body.txt',
            context)
    user.email_user(subject, body_text)

At the moment I am getting this error

(venv) PS C:\Users\Alex\PycharmProjects\pythonProjectTown\bboard> Python manage.py runserver
C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\db\models\base.py:321: RuntimeWarning: Model 'main.advuser_groups' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\db\models\base.py:321: RuntimeWarning: Model 'main.advuser_user_permissions' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\db\models\base.py:321: RuntimeWarning: Model 'main.advuser' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\db\models\base.py:321: RuntimeWarning: Model 'main.advuser_groups' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\db\models\base.py:321: RuntimeWarning: Model 'main.advuser_user_permissions' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\db\models\base.py:321: RuntimeWarning: Model 'main.advuser' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Alex\PycharmProjects\pythonProjectTown\venv\lib\site-packages\django\core\management\base.py", line 469, in check
    raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: ←[31;1mSystemCheckError: System check identified some issues:
←[0m
ERRORS:
←[31;1madmin.LogEntry.user: (fields.E300) Field defines a relation with model 'AdvUser', which is either not installed, or is abstract.←[0m
←[31;1mmain.AdvUser_groups: (fields.E336) The model is used as an intermediate model by 'main.AdvUser.groups', but it does not have a foreign key to 'AdvUser' or 'Group'.←[0m
←[31;1mmain.AdvUser_user_permissions: (fields.E336) The model is used as an intermediate model by 'main.AdvUser.user_permissions', but it does not have a foreign key to 'AdvUser' or 'Permission'.←[0m

System check identified 3 issues (0 silenced).

Please post your main models.py file.

Models.py


from django.db import models
from django.contrib.auth.models import AbstractUser
from django.dispatch import Signal
from .utilities import send_activation_notification

class AdvUser(AbstractUser):
    is_activated = models.BooleanField(default=True, db_index=True,
            verbose_name='Прошел активацию?')
    send_messages = models.BooleanField(default=True,
            verbose_name='Оповещать при новых комментариях?')
class Meta(AbstractUser.Meta):
    pass

user_registrated = Signal(providing_args=['instance'])

def user_registrated_dispatcher(sender, **kwargs):
    send_activation_notification(kwargs['instance'])


user_registrated.connect(user_registrated_dispatcher)
class AdvUser(AbstractUser):
    is_activated = models.BooleanField(default=True, db_index=True,
                                    verbose_name='Прошел активацию?')
    send_messages = models.BooleanField(default=True,
                                    verbose_name='Оповещать при новых комментариях?')

class Meta(AbstractUser.Meta):
    pass

class Rubric(models.Model):
    name = models.CharField(max_length=20, db_index=True, unique=True,
                            verbose_name='Название')
    order = models.SmallIntegerField(default=0, db_index=True,
                                 verbose_name='Порядок')
    super_rubric = models.ForeignKey('SuperRubric',
                                 on_delete=models.PROTECT, null=True, blank=True,
                                 verbose_name='Надрубрика')

class SuperRubricManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(super_rubric__isnull=True)


class SuperRubric(Rubric):
    object = SuperRubricManager()
    
    def __str__(self):
        return self.name
        
    class Meta:
        proxy = True
        ordering = ('order', 'name')
        verbose_name = 'Надрубрика'
        verbose_name_plural = 'Надрубрики'

class SubRubricManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(super_rubric__isnull=False)


class SubRubric(Rubric):
    object = SubRubricManager()
    
    def __str__(self):
        return '%s - %s' % (self.super_rubric, self.name)
    class Meta:
        proxy = True
        ordering = ('super_rubric__order', 'super_rubric__name', 'order', 'name')
        verbose_name = 'Подрубрика'
        verbose_name_plural = 'Подрубрики'

You’ve got a number of items here that aren’t properly indented or in appropriate locations. (Specifically, the two Meta class definitions.)

You also appear to have two separate classes inheriting from AbstractUser. That’s not going to work the way you may be thinking it will work. This is actually the cause of the errors being thrown.

Django is designed to only work with one base User model. The concept of Profile models is available if you need extra data specific to a subset of those users.

Also, you haven’t specified what version of Django you are using, but the use of the providing_args parameter in the Signal constructor has been removed.

1 Like

I use Django version - 3.2.16

I showed it to my teacher who gave me this assignment and he corrected some points:
He combined everything in the urls.py file into one line (if I express myself correctly)
I mean where is the line:

urlpatterns = [

urls.py:

from django.urls import path
from .views import index
from .views import other_page
from .views import BBLoginView
from .views import profile
from .views import BBLogoutView
from .views import ChangeUserInfoView
from .views import BBPasswordChangeView
from .views import RegisterUserView, RegisterDoneView
from .views import user_activate
from .views import DeleteUserView


app_name = 'main'

urlpatterns = [
    path('accounts/login', BBLoginView.as_view(), name='login'),
    path('<str:page>/', other_page, name='other'),
    path('', index, name='index'),
    path('accounts/profile/', profile, name='profile'),
    path('accounts/logout/', BBLogoutView.as_view(), name='logout'),
    path('accounts/profile/change/', ChangeUserInfoView.as_view(), name='profile_change'),
    path('accounts/profile/', profile, name='profile'),
    path('accounts/password/change/', BBPasswordChangeView.as_view(), name='password_change'),
    path('accounts/register/done/', RegisterDoneView.as_view(), name='register_done'),
    path('accounts/register/', RegisterUserView.as_view(), name='register'),
    path('accounts/register/done/', RegisterDoneView.as_view(), name='register_done'),
    path('accounts/register/', RegisterUserView.as_view(), name='register'),
    path('accounts/register/done/', RegisterDoneView.as_view(), name='register_done'),
    path('accounts/register/', RegisterUserView.as_view(), name='register'),
    path('accounts/register/activate/<str:sign>/', user_activate, name='register_activate'),
    path('accounts/profile/delete/', DeleteUserView.as_view(), name='profile_delete'),
]

And also in models.py removed everything that was in the bracket in this line:

user_registrated = Signal()

Before that it was like this:

user_registrated = Signal(providing_args=['instance'])

Having done all this, he launched a local server and we opened a page on the Internet. I saved this project to open it at home and continue working on it. I thought the problem was solved, but when I opened it at home I got the same error:

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files\Python37\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "C:\Program Files\Python37\lib\site-packages\django\apps\config.py", line 224, in create
    import_module(entry)
  File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bootstrap4'

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
    super().execute(*args, **options)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 96, in handle
    self.run(**options)
  File "C:\Program Files\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 103, in run
    autoreload.run_with_reloader(self.inner_run, **options)
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 638, in run_with_reloader
    start_django(reloader, main_func, *args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 623, in start_django
    reloader.run(django_main_thread)
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 329, in run
    self.run_loop()
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 335, in run
    next(ticker)
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 375, in tic
    for filepath, mtime in self.snapshot_files():
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 391, in sna
    for file in self.watched_files():
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 289, in wat
    yield from iter_all_python_module_files()
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 116, in ite
    return iter_modules_and_files(modules, frozenset(_error_files))
  File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 152, in ite
    if not path.exists():
  File "C:\Program Files\Python37\lib\pathlib.py", line 1329, in exists
    self.stat()
  File "C:\Program Files\Python37\lib\pathlib.py", line 1151, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] Синтаксическая ошибка в имени файла, имени папки или метке тома: '<frozen

What is the problem?

The key line of the traceback is this:

I do not quite understand what I need to fix, can you please tell me

Thank you for your replies, I really appreciate it

Side note: You have a lot of useless duplicate entries in your urlpatterns.

1 Like

You need to determine what the appropriate solution is.

Somewhere in your project, you’re making a reference to a module or package named bootstrap4. You either need to make sure that module or package is installed, or you need to correct the reference to refer to the right package. I wouldn’t know what the right answer would be for you.