modulenotfounderror:没有名为“apps.product.context\u processors”的模块

f45qwnt8  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(358)

我得到这个错误,我找不到是什么原因造成的。以下是回溯:

Traceback (most recent call last):
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args,**callback_kwargs)
  File "/Users/alex/projects/passtur/passtur/apps/core/views.py", line 9, in frontpage
    return render(request, 'core/frontpage.html', {'newest_products': newest_products})
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/template/base.py", line 168, in render
    with context.bind_template(self):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/template/context.py", line 240, in bind_template
    processors = (template.engine.template_context_processors +
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/template/engine.py", line 85, in template_context_processors
    return tuple(import_string(path) for path in context_processors)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/template/engine.py", line 85, in <genexpr>
    return tuple(import_string(path) for path in context_processors)
  File "/Users/alex/projects/passtur/venv/lib/python3.9/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'apps.product.context_processors'
[27/Apr/2021 21:43:33] "GET / HTTP/1.1" 500 110467

我的核心/views.py是:

from django.shortcuts import render

from apps.product.models import Product

def frontpage(request):
    newest_products = Product.objects.all()[0:8]

    return render(request, 'core/frontpage.html', {'newest_products': newest_products})

def contact(request):
    return render(request, 'core/contact.html')

我的context\u processors.py是:

from apps.product.models import Category

def menu_categories(request):
    categories = Category.objects.all()

    return {'menu_categories': categories}

应用程序目录结构为:

以及核心和产品应用程序文件夹结构的详细信息:

我应该补充一点,由于我正在使用django的旧版本(但在设置项目时没有明确说明)的教程,我不得不对apps.py文件进行一些更改,以便让它查找应用程序。我怀疑这可能是问题的原因,但我不知道如何解决它。我的核心/apps.py文件:

from django.apps import AppConfig

class CoreConfig(AppConfig):
    #default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.core'

和product.apps.py:

from django.apps import AppConfig

class ProductConfig(AppConfig):
    #default_auto_field = 'django.db.models.BigAutoField'
    name = 'apps.product'

我希望我已经提出了正确的信息,如果有人可以帮助我与这个具体问题,我将不胜感激。

j2qf4p5b

j2qf4p5b1#

context_processors.py 应该与 models.py 或者 apps.py 不在templates文件夹中

相关问题