uwsgi 错误与 ModuleNotFoundError 'xxx.context_processors' 使用自定义 context_processors
uwsgi error with ModuleNotFoundError 'xxx.context_processors' use customized context_processors
enter code here
我将我的项目放在服务器上并使用 uwsgi 尝试启动。
像.. uwsgi --http :8000 --module myDjangoProject.wsgi
它可以 运行,但是当我访问我的站点时,附加一个错误....
Internal Server Error: /
Traceback (most recent call last):
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "./apps/news/views.py", line 27, in index
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/base.py", line 169, in render
with context.bind_template(self):
File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/debug_toolbar/panels/templates/panel.py", line 41, in _request_context_bind_template
processors = template.engine.template_context_processors + self._processors
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/engine.py", line 85, in template_context_processors
return tuple(import_string(path) for path in context_processors)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/engine.py", line 85, in <genexpr>
return tuple(import_string(path) for path in context_processors)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'apps.cms.context_processors'
我认为我的 setting.py 有问题,我在我的项目中设计了我自己的 context_processors
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'front', 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
*'apps.cms.context_processors.user_profile_front',
'apps.cms.context_processors.leader_assignments_prompt',
'apps.news.context_processors.hot_article',*
],
'builtins':[
'django.templatetags.static',
],
'libraries': {
'news_filters': 'apps.news.templatetags.news_filters',
'cms_filters': 'apps.cms.templatetags.cms_filters',
},
},
},
我的项目可以 运行 与 manage.py 运行 服务器,当我删除这三行并使用 uwsgi 启动时,错误消失,但我设计的 context_processors失效..我该如何解决....
'apps.cms.context_processors.user_profile_front',
'apps.cms.context_processors.leader_assignments_prompt',
'apps.news.context_processors.hot_article'
我通过在 uwsgi 中添加 --pythonpath /opt/myDjangoProject/ 来解决它,我的项目的绝对路径在哪里
enter code here
我将我的项目放在服务器上并使用 uwsgi 尝试启动。
像.. uwsgi --http :8000 --module myDjangoProject.wsgi
它可以 运行,但是当我访问我的站点时,附加一个错误....
Internal Server Error: /
Traceback (most recent call last):
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "./apps/news/views.py", line 27, in index
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/base.py", line 169, in render
with context.bind_template(self):
File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/debug_toolbar/panels/templates/panel.py", line 41, in _request_context_bind_template
processors = template.engine.template_context_processors + self._processors
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/engine.py", line 85, in template_context_processors
return tuple(import_string(path) for path in context_processors)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/template/engine.py", line 85, in <genexpr>
return tuple(import_string(path) for path in context_processors)
File "/var/www/myDjangoProject/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'apps.cms.context_processors'
我认为我的 setting.py 有问题,我在我的项目中设计了我自己的 context_processors
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'front', 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
*'apps.cms.context_processors.user_profile_front',
'apps.cms.context_processors.leader_assignments_prompt',
'apps.news.context_processors.hot_article',*
],
'builtins':[
'django.templatetags.static',
],
'libraries': {
'news_filters': 'apps.news.templatetags.news_filters',
'cms_filters': 'apps.cms.templatetags.cms_filters',
},
},
},
我的项目可以 运行 与 manage.py 运行 服务器,当我删除这三行并使用 uwsgi 启动时,错误消失,但我设计的 context_processors失效..我该如何解决....
'apps.cms.context_processors.user_profile_front',
'apps.cms.context_processors.leader_assignments_prompt',
'apps.news.context_processors.hot_article'
我通过在 uwsgi 中添加 --pythonpath /opt/myDjangoProject/ 来解决它,我的项目的绝对路径在哪里