Django-fr

Forum

#1 14-03-2016 19:24:32

GrandGTO
Membre
Inscription : 14-03-2016
Messages : 3

WSGI - Error 500

Bonjour à vous tous,

Voici mon problème, je débute tout juste sur Django 1.8, et bien que je suis parvenu à créer ma première application, je coince vraiment sur les étapes à suivre pour la mise en production. J'ai installé Apache ainsi que WSGI, paramétré mon Virtualhost, mais j'obtiens une erreur 500. Ca fait depuis une semaine que je me tire les cheveux !

wsgi.py :

"""
WSGI config for cjaouani 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.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cjaouani.settings")

application = get_wsgi_application()

setting.py

"""
Django settings for cjaouani project.

Generated by 'django-admin startproject' using Django 1.8.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%o93-wwhh3pt-pv9w#t^7==q=hy=n&6^#ioo4i$l=s=_bq=uc&'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['www.cjaouani.fr', '.cjaouani.fr']


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'home'
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'cjaouani.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'cjaouani.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '****',
        'USER': '******',
        'PASSWORD': '****',
        'HOST': '127.0.0.1',
        'PORT': '',
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'fr-FR'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

/etc/apache2/site-available/cjaouani.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin c.jaouani@gmail.com
    ServerName cjaouani.fr
    DocumentRoot /home/django-project/cjaouani/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Alias /static/ /var/www/cjaouani/static/
    Alias /uploads/ /var/www/cjaouani/uploads/

    WSGIScriptAlias / /home/django-project/cjaouani/cjaouani/wsgi.py
    <Directory /home/django-project/cjaouani/>
       <Files wsgi.py>
            Require all granted
       </Files>
    </Directory>
</VirtualHost>
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Voici les logs de mon apache :

root@vps255895:~# tail -f /var/log/apache2/error.log
[Mon Mar 14 18:48:46.959730 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959744 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in __getattr__, referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959840 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]     self._setup(name), referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959853 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 44, in _setup, referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959870 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]     self._wrapped = Settings(settings_module), referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959878 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 92, in __init__, referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959890 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]     mod = importlib.import_module(self.SETTINGS_MODULE), referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959898 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module, referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959939 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701]     __import__(name), referer: http://cjaouani.fr/
[Mon Mar 14 18:48:46.959973 2016] [wsgi:error] [pid 6504:tid 139845225649920] [client 77.147.156.191:62701] ImportError: No module named cjaouani.settings, referer: http://cjaouani.fr/

Merci beaucoup pour votre aide !

Dernière modification par GrandGTO (14-03-2016 19:33:41)

Hors ligne

#2 16-03-2016 22:16:54

Xavier Ordoquy
Administrateur
Lieu : Puteaux, France
Inscription : 12-10-2011
Messages : 312
Site Web

Re : WSGI - Error 500

ImportError: No module named cjaouani.settings, referer: http://cjaouani.fr/

Manifestement le module cjaouani n'est pas dans le path de ton mod_wsgi.
Une petite recherche google te renseignera comment changer les chemins Python pour que ton projet soit pris en compte.

Hors ligne

#3 17-03-2016 08:46:27

GrandGTO
Membre
Inscription : 14-03-2016
Messages : 3

Re : WSGI - Error 500

Merci, oui en effet c'est bien ça.
J'ai rajouté une ligne dans le fichier WSGI de Django.
Merci !

Hors ligne

Pied de page des forums