feldroy / django-crash-starter

The Cookiecutter template for the Django Crash Course tutorial by Daniel and Audrey Feldroy.
https://www.feldroy.com/products/django-crash-course
94 stars 38 forks source link

RuntimeError: Model class shop.models.Category doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. #147

Open foscraft opened 3 years ago

foscraft commented 3 years ago

What happened?

Am having the following this error. Am trying to build an online shop using the cookiecutter.

python manage.py runserver Watching for file changes with StatReloader INFO 2020-08-23 11:55:13,654 autoreload 13959 139651660433216 Watching for file changes with StatReloader Performing system checks...

Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/usr/lib/python3.8/threading.py", line 870, in run self._target(*self._args, *self._kwargs) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(args, kwargs) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run self.check(display_num_errors=True) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/management/base.py", line 392, in check all_issues = self._run_checks( File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/management/base.py", line 382, in _run_checks return checks.run_checks(kwargs) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/checks/registry.py", line 72, in run_checks new_errors = check(app_configs=app_configs) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 407, in check for pattern in self.url_patterns: File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/utils/functional.py", line 48, in get res = instance.dict[self.name] = self.func(instance) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 588, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/utils/functional.py", line 48, in get res = instance.dict[self.name] = self.func(instance) File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/resolvers.py", line 581, in urlconf_module return import_module(self.urlconf_name) File "/usr/lib/python3.8/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 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "/home/reus/Documents/WORK/elimubora/config/urls.py", line 28, in path('cart/', include('elimubora.cart.urls',namespace='cart')), File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include urlconf_module = import_module(urlconf_module) File "/usr/lib/python3.8/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 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "/home/reus/Documents/WORK/elimubora/elimubora/cart/urls.py", line 2, in from . import views File "/home/reus/Documents/WORK/elimubora/elimubora/cart/views.py", line 4, in from elimubora.cart.cart import Cart File "/home/reus/Documents/WORK/elimubora/elimubora/cart/cart.py", line 3, in from shop.models import Book File "/home/reus/Documents/WORK/elimubora/elimubora/shop/models.py", line 4, in class Category(models.Model): File "/home/reus/Documents/WORK/env/lib/python3.8/site-packages/django/db/models/base.py", line 112, in new raise RuntimeError( RuntimeError: Model class shop.models.Category doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

My apps look like this: DJANGO_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.sites", "django.contrib.messages", "django.contrib.staticfiles",

"django.contrib.humanize", # Handy template tags

"django.contrib.admin",
"django.forms",

]

THIRD_PARTY_APPS = [ "crispy_forms", "allauth", "allauth.account", "allauth.socialaccount", ]

LOCAL_APPS = [ "elimubora.users.apps.UsersConfig", "elimubora.shop.apps.ShopConfig", "elimubora.cart.apps.CartConfig", "elimubora.orders.apps.OrdersConfig",

Your stuff: custom apps go here

]

What should've happened instead?

Steps to reproduce

luzfcb commented 3 years ago

@Nyaribari https://stackoverflow.com/a/61189995

foscraft commented 3 years ago

@luzfcb I have done that but the error still persists. apps.py:

from django.apps import AppConfig

class ShopConfig(AppConfig):
    name = 'elimubora.shop'

urls.py:

from django.urls import path
from . import views

app_name='shop'

urlpatterns = [
    path(
    route='',
    view=views.book_list,
    name='book_list'
    ),
    path(route='<slug:category_slug>/',
    view=views.book_list,
    name='book_list_by_category'
    ),
    path(route='<int:id>/<slug:slug>/',
    view=views.book_detail,
    name='book_detail'),
]

I have the app in the project-slug:

(env) (base) reus@reus:~/Documents/WORK/elimubora$ ls elimubora/
cart         contrib      media   __pycache__  static     users
conftest.py  __init__.py  orders  shop         templates  utils