Random error 500

We use Apache + mod_wsgi to host our Django application.

Apache:

WSGIScriptAlias / /home/rls/django_wsgi.py

django_wsgi.py:

 import os, sys sys.path.append('data/misc/django') os.environ['DJANGO_SETTINGS_MODULE'] = 'rls.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

Everything works fine, but sometimes we get 500 Internal Server Error with this in the logs:

 mod_wsgi (pid=4825): Exception occurred processing WSGI script '/home/rls/django_wsgi.py'. Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 230, in __call__ self.load_middleware() File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 33, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 276, in __getattr__ self._setup() File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 40, in _setup self._wrapped = Settings(settings_module) File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 75, in __init__ raise ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)) ImportError: Could not import settings 'rls.settings' (Is it on sys.path? Does it have syntax errors?): No module named rls.settings 

Of course, there are no syntax errors in the settings.py parameters, since it loads fine every time. What am I missing? Many thanks for your help.

+4
source share
1 answer

Try setting the absolute path to the directory containing the settings.py file. In your case, there should be something like:

 sys.path.append('/%s/data/misc/django'%ROOT_2_DATA) 

You should also verify that the apache group has read / write permissions to the folder.

+2
source

Source: https://habr.com/ru/post/1342018/


All Articles