daniel correa
daniel correa

Reputation: 1

ModuleNotFoundError: No module named 'products'

I'm a newbie to Django. I'm following a tutorial where I should create a model class called products.

This is what I've included in my models.py document inside my APP called Products:

class Products (models.Model):
title = models.TextField()
description = models.TextField()
price = models.TextField()

Then I added the APP to INSTALLED APPS in my setting.py document:

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

    #third party

    #own
    'products',

However, when I tried to run the following command on my terminal I get an error:

(env) dcorreavi@dcorreavi src % python manage.py makemigrations
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 "/Users/dcorreavi/Dev/trydjano/python-virtual-environments/env/lib/python3.8/site- 
packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/dcorreavi/Dev/trydjano/python-virtual-environments/env/lib/python3.8/site- 
packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/Users/dcorreavi/Dev/trydjano/python-virtual-environments/env/lib/python3.8/site- 
packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/dcorreavi/Dev/trydjano/python-virtual-environments/env/lib/python3.8/site- 
packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/Users/dcorreavi/Dev/trydjano/python-virtual-environments/env/lib/python3.8/site- 
packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File 
"/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", 
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'products'

Upvotes: 0

Views: 3440

Answers (4)

onesadlittleboy
onesadlittleboy

Reputation: 3

comment out'products', from settings.py.

run this command first from your source folder (where manage.py is):

python manage.py startapp products

then go back and add 'products', in settings.py

Upvotes: 0

Viktor
Viktor

Reputation: 1

You can try installing the following packages

pip install django-extensions
pip install ipython

go to settings.py -> INSTALLED_APPS and add django_extensions app

run via ./manage.py shell_plus

django-extensions automatically imports the models and classes we need (for example, ProductCategory, Product and others, which you will learn about later)

ipython - for the convenience of using the terminal, it allows you to enter the clear, cd, pwd commands without opening a new terminal

Upvotes: 0

kitchen800
kitchen800

Reputation: 227

'products.apps.ProductsConfig' added to installed app section in settings

Upvotes: 0

Marcelo
Marcelo

Reputation: 87

Try this:

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

    'products.apps.ProductsConfig',
]

instead of only products

Upvotes: 1

Related Questions