G
G
Grigory Dikiy2017-01-24 11:44:29
Django
Grigory Dikiy, 2017-01-24 11:44:29

Django wrapping modules in a folder?

Good day! I decided to clean up and structure the code a bit. It was decided to create an apps park, where I would store all my applications, so that there would be no mixing with templates and static, etc. But after modifications I get an error:

ImportError at /
No module named 'cart'
Request Method:	GET
Request URL:	http://89.223.28.112/
Django Version:	1.10.5
Exception Type:	ImportError
Exception Value:	
No module named 'cart'
Exception Location:	/home/dikiigr/posuda_shop/env/lib/python3.5/importlib/__init__.py in import_module, line 126
Python Executable:	/home/dikiigr/posuda_shop/env/bin/python3
Python Version:	3.5.2
Python Path:	
['/home/dikiigr/posuda_shop/engine',
 '/home/dikiigr/posuda_shop/env/bin',
 '/home/dikiigr/posuda_shop/env/lib/python35.zip',
 '/home/dikiigr/posuda_shop/env/lib/python3.5',
 '/home/dikiigr/posuda_shop/env/lib/python3.5/plat-x86_64-linux-gnu',
 '/home/dikiigr/posuda_shop/env/lib/python3.5/lib-dynload',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages']

But I can’t figure out what is the reason for such an action:
urls.py configured it seems to be correct:
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^attributes/', include('apps.attributes.urls', namespace='attributes')),
    url(r'^cart/', include('apps.cart.urls', namespace='cart')),
    url(r'^menu/', include('apps.menu.urls', namespace='menu')),
    url(r'^orders/', include('apps.orders.urls', namespace='orders')),
    url(r'^account/', include('apps.accounts.urls', namespace='accounts')),
    url(r'^pages/', include('apps.pages.url', namespace='pages')),
    url(r'^redactor/', include('redactor.urls')),
    url(r'^', include('apps.products.urls', namespace='products')),
]

Installed applications also seem to be correct:
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'redactor',
    'apps.menu',
    'apps.products',
    'apps.cart',
    'apps.orders',
    'apps.accounts',
    'apps.attributes',
    'apps.pages'
]

The new structure is as follows:
8013a03bdd2c4a9d9162448e10591ca0.png
That is, the __init__.py file is located in the root of the apps folder.
Who has any idea about this?
Traceback:

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/dikiigr/posuda_shop/engine/apps/products/views.py" in main
  20.         'section': 'sections/main/main.html'

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/template/loader.py" in render_to_string
  68.     return template.render(context, request)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/template/backends/django.py" in render
  66.             return self.template.render(context)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/template/base.py" in render
  206.                 with context.bind_template(self):

File "/usr/lib/python3.5/contextlib.py" in __enter__
  59.             return next(self.gen)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/template/context.py" in bind_template
  232.         processors = (template.engine.template_context_processors +

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/utils/functional.py" in __get__
  35.         res = instance.__dict__[self.name] = self.func(instance)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/template/engine.py" in template_context_processors
  91.         return tuple(import_string(path) for path in context_processors)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/template/engine.py" in <genexpr>
  91.         return tuple(import_string(path) for path in context_processors)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/site-packages/django/utils/module_loading.py" in import_string
  20.     module = import_module(module_path)

File "/home/dikiigr/posuda_shop/env/lib/python3.5/importlib/__init__.py" in import_module
  126.     return _bootstrap._gcd_import(name[level:], package, level)

Exception Type: ImportError at /
Exception Value: No module named 'cart'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Dikiy, 2017-01-24
@frilix

Problem solved! Did not set the path in the list of context processes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question