Django - AttributeError:' module'对象没有属性' TEMPLATE_CONTEXT_PROCESSORS'

时间:2016-12-22 17:22:38

标签: python django nginx

我有一个崩溃的生产的python应用程序。当试图打开网站时,我得到了一个502坏网关。尝试使用python manage.py restart重新启动django应用程序后,出现以下错误。

 Traceback (most recent call last):


File "manage.py", line 23, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute
    settings.INSTALLED_APPS
  File "/usr/lib64/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/usr/lib64/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/lib64/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/ringier/expat/expat/expat/expat/settings/__init__.py", line 12, in <module>
    from expat.settings.production import *
  File "/ringier/expat/expat/expat/expat/settings/production.py", line 4, in <module>
    from expat.settings.base import *
  File "/ringier/expat/expat/expat/expat/settings/base.py", line 89, in <module>
    TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
AttributeError: 'module' object has no attribute 'TEMPLATE_CONTEXT_PROCESSORS'

我没有改变代码和配置上的任何内容,我不知道为什么会发生这种情况。我检查了类似的错误,但他们没有解决这个问题。

由于

编辑:

base.py

...
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
    'django.core.context_processors.request',
    'home.context_processors.system_config',)
...

global_settings = https://github.com/django/django/blob/master/django/conf/global_settings.py

编辑2:

我删除了对global_settings.TEMPLATE_CONTEXT_PROCESSORS的调用。在这之后,我不得不安装从base.py调用的许多模块,这非常奇怪,因为网站工作得很好,我不知道这些模块是如何丢失的...... 安装完所有模块后,我可以达到无法安装postgres模块的程度

Traceback (most recent call last):
  File "manage.py", line 23, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib64/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/usr/lib64/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 119, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 316, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/lib64/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/lib64/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/lib64/python2.7/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2

我非常感谢帮助,因为该网站正在推出,现在已超过12小时。

1 个答案:

答案 0 :(得分:0)

看起来你没有像以前那样在同一个虚拟环境中重启Django,因为Django版本似乎已经改变了,你得到psycopg2的导入错误。

听起来你可能在制作中使用runserver。你不应该这样做,这是不安全的。 Django docs描述了如何正确部署Django。