Configuration problems with django and mod_wsgi

I am having problems getting django to work with apache 2.2 with mod_wsgi. Django is installed and mod_wsgi too. I even see page 404 when accessing the path, and I can log in to django admin. But if I want to install the tag module, I get the following error:

Traceback (most recent call last): File "setup.py", line 49, in <module> version_tuple = __import__('tagging').VERSION File "/home/jim/django-tagging/tagging/__init__.py", line 3, in <module> from tagging.managers import ModelTaggedItemManager, TagDescriptor File "/home/jim/django-tagging/tagging/managers.py", line 5, in <module> from django.contrib.contenttypes.models import ContentType File "/usr/lib/python2.5/site-packages/django/contrib/contenttypes/models.py", line 1, in <module> from django.db import models File "/usr/lib/python2.5/site-packages/django/db/__init__.py", line 10, in <module> if not settings.DATABASE_ENGINE: File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 269, 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 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings 

My httpd.conf:

  Alias /media/ /home/jim/django/mysite/media/ <Directory /home/jim/django/mysite/media> Order deny,allow Allow from all </Directory> Alias /admin/media/ "/usr/lib/python2.5/site-packages/django/contrib/admin/media/" <Directory "/usr/lib/python2.5/site-packages/django/contrib/admin/media/"> Order allow,deny Allow from all </Directory> WSGIScriptAlias /dj /home/jim/django/mysite/apache/django.wsgi <Directory /home/jim/django/mysite/apache> Order deny,allow Allow from all </Directory> 

My django.wsgi:

 import sys, os sys.path.append('/home/jim/django') sys.path.append('/home/jim/django/mysite') os.chdir('/home/jim/django/mysite') os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

I am trying to get this to work from a few days and read a few blogs and answers here, but nothing worked.

Edit:

Now I tried this with this blog post , and my wsgi file now looks like this:

 import sys sys.path.insert(0, '/home/jim/django/mysite') sys.path.insert(0, '/home/jim/django') import settings import django.core.management django.core.management.setup_environ(settings) utility = django.core.management.ManagementUtility() command = utility.fetch_command('runserver') command.validate() import django.conf import django.utils django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE) import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

admin still works, but I get the same error when I try to install the tag module.

+5
source share
2 answers

At first,

  • Since your administrator is working, setting up with wsgi is good. Do not bother to change / edit it.

To make sure that this is not a problem with installing Apache / mod-wsgi, you can start the development server from the production machine

 python manage.py runserver 0:8080 

Then point the browser to

 http://yoursite.com:8080/ 

You should see exactly the same behavior.

Then

To debug this problem:

  • In the python shell on your server, try import tagging . Obviously, an error occurs from your import tagging trace, and therefore the settings cannot be imported.

  • Then just uninstall the package containing the tags and make a new installation with the next command that knows how to install the packages, well.

.

 sudo pip install django-tagging 
+4
source

Have you read the Graham Dumpleton blog post on Django and WSGI ? It describes fairly well some common configuration issues, and is especially true for mysite.settings vs. settings .

UPDATE: Please read Graham Dumpleton's excellent comments below.

UPDATE 2: As both Graham and Guru Becoming pointed out, the issue is not related to WSGI. This is a problem with installing django-tagging . Grab a consultation and use pip to install django-tagging .

+4
source

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


All Articles