Bonjour,

Je suis actuellement en train de développer un site.
La version en préprod (la prod n'est pas encore en place) est accessible et fonctionne globalement bien mais j'y ai quelques soucis que je n'ai pas avec le serveur de django (pour l'administration, quelques erreurs 500 et autres).

Pour régler plus facilement ces problèmes j'ai donc décidé d'utiliser apache2 comme serveur sur ma machine de développement.

Seulement switchant vers apache2, j'ai rencontré quelques problèmes d'erreur 500 (server error) avec le script wsgi.py sous mon Ubuntu (partie développement).
Voyez plutôt :


Le log d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1] mod_wsgi (pid=8459): Exception occurred processing WSGI script '/home/user/myproject/htdocs/myproject/wsgi.py'.
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     self.load_middleware()
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 47, in load_middleware
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     mw_class = import_by_path(middleware_path)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 26, in import_by_path
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     sys.exc_info()[2])
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 21, in import_by_path
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     module = import_module(module_path)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     __import__(name)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/middleware.py", line 3, in <module>
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     from django.contrib.auth.backends import RemoteUserBackend
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py", line 3, in <module>
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     from django.contrib.auth.models import Permission
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py", line 48, in <module>
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     class Permission(models.Model):
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 96, in __new__
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     new_class.add_to_class('_meta', Options(meta, **kwargs))
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 264, in add_to_class
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     value.contribute_to_class(cls, name)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 124, in contribute_to_class
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 34, in __getattr__
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     return getattr(connections[DEFAULT_DB_ALIAS], item)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 198, in __getitem__
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     backend = load_backend(db['ENGINE'])
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 113, in load_backend
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     return import_module('%s.base' % backend_name)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     __import__(name)
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 14, in <module>
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1]     from django.db import utils
[Sat Jul 19 04:03:41 2014] [error] [client 127.0.0.1] ImproperlyConfigured: Error importing module django.contrib.auth.middleware: "cannot import name utils"
Le code :
Avant mon fichier wsgi.py était comme ceci (et est toujours comme ceci dans la préprod d'ailleurs) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""
WSGI config for myproject project.
 
It exposes the WSGI callable as a module-level variable named ``application``.
 
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
 
import django.conf.global_settings as DEFAULT_SETTINGS
 
import os, sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
 
 
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
 
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir))
 
sys.path.append(PROJECT_PATH)
J'ai d'abord eu une erreur due à mon myproject.settings (qui passait pourtant en préprod sans soucis.)

Je l'ai donc modifié ainsi :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""
WSGI config for myproject project.
 
It exposes the WSGI callable as a module-level variable named ``application``.
 
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
 
import django.conf.global_settings as DEFAULT_SETTINGS
 
import os, sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
 
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir))
 
sys.path.append(PROJECT_PATH)
 
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
J'ai alors passé l'erreur suivante mais uniquement pour aboutir à celle présente dans le log d'erreur plus haut.

Voici aussi mon settings.py en complément d'information :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Django settings for myproject project.
 
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
 
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
 
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
 
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'),
)
 
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
 
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
 
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
 
TEMPLATE_DEBUG = True
 
ALLOWED_HOSTS = ['myproject.fr', 'dev.myproject.fr', '127.0.0.1']
 
# Admins :
 
ADMINS = (
    ('first_name last_name', 'pseudo@mail.fr'),
)
 
# Application definition
 
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'main',  # nom de mon app
)
 
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
 
ROOT_URLCONF = 'myproject.urls'
 
WSGI_APPLICATION = 'myproject.wsgi.application'
 
 
# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
 
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
 
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
 
LANGUAGE_CODE = 'en-us'
 
TIME_ZONE = 'Europe/Paris'
 
USE_I18N = True
 
USE_L10N = True
 
USE_TZ = True
 
 
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
 
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')
 
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
#    os.path.join(BASE_DIR, 'myproject/static'),
)
 
# # Media Files (pictures)
MEDIA_URL = '/media/'
 
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
 
APPEND_SLASH = True
Mon matériel :
J'utilise deux machines :
- un Raspberry pi avec :
-Arch ARM comme OS (dérivée d'Archlinux).
-Apache 2.4.9 (pas apache2 il me semble, celui-ci n'étant pas disponible pour cette machine)
-Python, les versions 3.4 et 2.7 sont installées, mais celle utilisée par défaut semble être la 3.4 (celle qui est utilisée en lançant juste "python" dans la console?).
-django 1.6.5

-Un Laptop sous Ubuntu avec :
-apache 2.2.22 (apache2)
-Python, avec les versions 3.2 et 2.7, celle se lançant par défaut en tapant "python" dans le shell étant la 2.7
-django 1.6.0

Sur l'une et l'autre de mes machines j'utilise git pour ma gestion de projet.

Se pourrait-il que le problème vienne des changements de version d'une machine à l'autre?
Si oui de quel changement de version? Est-il possible de régler le problème et de faire une version de mon projet qui soit fonctionnelle sur l'une ou l'autre de mes machines sans changer de versions?
Quelle marche à suivre pourriez-vous me conseiller?

Merci d'avance pour votre aide