Полное сообщение об ошибке:
Exception ignored in thread started by: <function check_errors.<locals>.wrapper at 0x000001967F417820>
Traceback (most recent call last):
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
self.check(display_num_errors=True)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\core\management\base.py", line 356, in check
all_issues = self._run_checks(
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
return check_method()
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\urls\resolvers.py", line 254, in check
for pattern in self.url_patterns:
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\utils\functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
return import_module(self.urlconf_name)
File "c:\python38\lib\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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\ALEX GEORGE\Dev\cfehome\src\trydjango\urls.py", line 19, in <module>
from src.products.views import product_detail_view
File "C:\Users\ALEX GEORGE\Dev\cfehome\src\products\views.py", line 2, in <module>
from .models import Product
File "C:\Users\ALEX GEORGE\Dev\cfehome\src\products\models.py", line 5, in <module>
class Product(models.Model):
File "C:\Users\ALEX GEORGE\Dev\cfehome\lib\site-packages\django\db\models\base.py", line 115, in __new__
raise RuntimeError(
RuntimeError: Model class src.products.models.Product doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Я использовал решение, которое было упомянуто ранее, как использование django .contrib.sites и установка SITE ID = 1, но я все еще получаю та же ошибка. Мои настройки выглядят так:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# own
'pages',
'products'
]
SITE_ID = 1;
Я получил эту ошибку, когда создал каталог продукта внутри каталога шаблонов и назвал шаблон как продукт. html. Мои приложения зовут продукты. введите код здесь Вот моя модель
from django.db import models
# Create your models here.
class Product(models.Model):
title = models.CharField(max_length=120) # max_length is required
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2, max_digits=10000)
summary = models.TextField(blank=False, null=False)
featured = models.BooleanField() # null=True, default= True
вот мой взгляд на продукты
from django.shortcuts import render
from .models import Product
# Create your views here.
def product_detail_view(request):
obj = Product.objects.get(id=1)
context = {
'title': obj.title,
'description': obj.description
}
return render(request, "product/detail.html", context)
вот мои страницы приложения вид
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def home_view(request, *args, **kwargs):
print(args, kwargs)
print(request.user)
# return HttpResponse("<h1>Hello World</h1>") # html string code
return render(request, "home.html")
def contact_view(request, *args, **kwargs):
return render(request, "contact.html")
def about_view(request, *args, **kwargs):
my_context = {
"my_text": "This is about us",
"my_number": 123,
"my_list": [123, 3223, 1323]
}
return render(request, "about.html", my_context)