首页 > 解决方案 > 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'

标签: pythonpython-3.xdjango

解决方案


'products.apps.ProductsConfig' 添加到设置中已安装的应用程序部分


推荐阅读