2017-02-02 53 views
0

我運行Django == 1.10.4網站與4種不同的語言。他們每個人都有自己的領域。他們中只有2或3人同時工作。Django populate()不可重入多語言設置與不同的域

這是後我殺了我的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進程後,有些域正在工作,有些無法正常工作。每個域都訪問相同的源代碼和相同的數據庫。所以我認爲源代碼沒有問題,因爲那些直接運行的站點沒有任何問題。

回答

0

這看起來不像Django問題,但mod_wsgi的配置錯誤 - 它看起來像您的應用程序可能運行在相同的解釋器中併發生衝突。

你的Apache/mod_wsgi配置如何?特別感興趣的是應該打開daemon mode,並且每個站點的守護進程都是分開的。 (See that directive's docs.

此外,我建議尋找服務與Apache/mod_wsgi以外的其他應用程序 - Nginx + uWSGI是我的首選武器。

+1

你說得對。我爲每個站點運行一個不同的守護進程,一切都運行良好。謝謝! –