Django populate()在具有不同域的多语言设置中不可重入

时间:2017-02-02 14:06:34

标签: django multilingual

我使用4种不同语言运行Django == 1.10.4网站。他们每个人都有自己的域名。其中只有2或3个同时工作。一个或多个失败,出现此错误:

这是我杀死wsgi进程并第一次访问该页面后出现的错误:

mod_wsgi (pid=8416): Target WSGI script '/var/www/user324/htdocs/ukmypagecom/app.wsgi' cannot be loaded as Python module.
 mod_wsgi (pid=8416): Exception occurred processing WSGI script '/var/www/user324/htdocs/ukmypagecom/app.wsgi'.
 Traceback (most recent call last):
   File "/var/www/user324/htdocs/ukmypagecom/app.wsgi", line 11, in <module>
     application = django.core.wsgi.get_wsgi_application()
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
     apps.populate(settings.INSTALLED_APPS)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
     app_config.import_models(all_models)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
     self.models_module = import_module(models_module_name)
   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
     class AbstractBaseUser(models.Model):
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/db/models/base.py", line 119, in __new__
     new_class.add_to_class('_meta', Options(meta, app_label))
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/db/models/base.py", line 316, in add_to_class
     value.contribute_to_class(cls, name)
   File "/var/www/user324/priv/venv/myvenv/lib/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 "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
     return getattr(connections[DEFAULT_DB_ALIAS], item)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
     backend = load_backend(db['ENGINE'])
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/db/utils.py", line 134, in load_backend
     raise ImproperlyConfigured(error_msg)
 ImproperlyConfigured: 'django.contrib.gis.db.backends.mysql' isn't an available database backend.
 Try using 'django.db.backends.XXX', where XXX is one of:
     'mysql', 'oracle', 'postgresql', 'sqlite3'
 Error was: cannot import name GEOSException

每次重新加载页面后,我只收到此错误:

 mod_wsgi (pid=8416): Target WSGI script '/var/www/user324/htdocs/ukmypagecom/app.wsgi' cannot be loaded as Python module.
 mod_wsgi (pid=8416): Exception occurred processing WSGI script '/var/www/user324/htdocs/ukmypagecom/app.wsgi'.
 Traceback (most recent call last):
   File "/var/www/user324/htdocs/ukmypagecom/app.wsgi", line 11, in <module>
     application = django.core.wsgi.get_wsgi_application()
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
     apps.populate(settings.INSTALLED_APPS)
   File "/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
     raise RuntimeError("populate() isn't reentrant")
 RuntimeError: populate() isn't reentrant

这是我的设置文件查找每个域的方式。

#settings_en.py
from base_settings import *

ALLOWED_HOSTS = ['127.0.0.1', '.example.com' ]
LANGUAGE_CODE = 'en-GB'
ROOT_URLCONF = 'myproject.base_urls'
SITE_ID = 18

#settings_pl.py
from base_settings import *

ALLOWED_HOSTS = ['127.0.0.1', '.example.com' ]
LANGUAGE_CODE = 'pl-PL'
ROOT_URLCONF = 'myproject.base_urls'
SITE_ID = 19

#settings_xx.py
...

这就是我的app.wsgi对每个域的看法

#english version

#!/usr/bin/python
import sys, os

sys.path.insert(0, '/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages') #virtualenv
sys.path.insert(0, '/var/www/user324/priv/mysourcecode') #sourcecode

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings_en'

import django.core.wsgi
application = django.core.wsgi.get_wsgi_application()


#polish version
#!/usr/bin/python
import sys, os

sys.path.insert(0, '/var/www/user324/priv/venv/myvenv/lib/python2.7/site-packages')
sys.path.insert(0, '/var/www/user324/priv/mysourcecode')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings_pl'

import django.core.wsgi
application = django.core.wsgi.get_wsgi_application()

知道这里出了什么问题吗?

在我重新启动wsgi进程后,某些域正在运行,有些域无效。每个域都访问相同的源代码和相同的数据库。所以我认为源代码没有问题,因为那些直接运行的站点没有任何问题。

1 个答案:

答案 0 :(得分:0)

这看起来不像Django问题,但是对mod_wsgi的配置错误 - 看起来您的应用程序可能在同一个解释器中运行并且存在冲突。

你的Apache / mod_wsgi是如何配置的?特别感兴趣的是,应该打开daemon mode并为每个站点分离守护进程。 (See that directive's docs.

另外,我建议用Apache / mod_wsgi之外的其他东西来研究你的应用程序--Nginx + uWSGI是我的首选武器。