2010-11-16 10 views
5

Ho problemi nell'impostare wgsi con django. Sto seguendo questo http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/. Tuttavia sono ancora molto confuso su dove inserire il file .wsgi e se ho bisogno di impostare sys.path. L'ho provato sia direttamente all'esterno che all'interno della web root e non riesco a far funzionare nulla come previsto.Percorsi Django WGSI

# /home/ben/public_html/django_test/testproject/apache/django.wsgi: 

import os 
import sys 

os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

Relivant apache conf:

DocumentRoot "/home/ben/public_html/django_test/testproject/" 
WSGIScriptAlias/"/home/ben/public_html/django_test/testproject/apache/django.wsgi" 

Apache Logs Error (standard Pagina apache 500):

ImportError: Could not import settings 'testproject.settings' (Is it on sys.path? ... 

posso da Get Django ad almeno gettare un errore di essa la propria by utilizzando questo:

import os 
import sys 

path = '/home/ben/public_html/django_test/testproject' 
if path not in sys.path: 
    sys.path.append(path) 

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

che ha portato in questa pagina di errore django:

ImportError at /admin/ 
No module named testproject.urls 

risposta

8

ho messo la WSGI allo stesso livello di settings.py, e si presenta così:

import os 
import sys 

sys.path.insert(0,os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2])) 


os.environ['DJANGO_SETTINGS_MODULE'] = 'yourprojectname.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

questo è il file apache conf:

NameVirtualHost *:80 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName www.yourprojectname.com 
    Alias /media/ /home/diegueus9/workspace/yourprojectname/media/ 

    <Directory /home/diegueus9/workspace/yourprojectname/media/> 
     Order deny,allow 
     Allow from all 
    </Directory> 

    WSGIScriptReloading On 
    WSGIDaemonProcess yourprojectname 
    WSGIProcessGroup yourprojectname 
    WSGIApplicationGroup yourprojectname 
    WSGIPassAuthorization On 

    WSGIScriptAlias//home/diegueus9/workspace/yourprojectname/yourfile.wsgi 
    ErrorLog /var/log/apache2/yourprojectname-error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel debug 

    CustomLog /var/log/apache2/yourprojectname-access.log combined 

</VirtualHost> 
+0

Questo dà un Apache 500. provato anche l'impostazione 'os.environ [ 'DJANGO_SETTINGS_MODULE '] =' testproject.settings ' '. ma senza fortuna. – Keyo

+0

modifica la mia risposta. – diegueus9

1

Here is a nice tutorial che mostra come utilizzare mod_wsgi con Django e anche alcuni altri elementi non correlati a questa domanda.

1

Come una soluzione rapida è possibile, accanto ad aggiungere questo a sys.path:

path = '/home/ben/public_html/django_test/testproject' 

aggiungere anche questo:

path2 = '/home/ben/public_html/django_test' 

È inoltre possibile modificare il percorso di Python nel vostro Apache VirtualHost:

WSGIDaemonProcess [...] python-path=/home/ben/public_html/django_test 

Ma dovresti anche rivedere i documenti mod_wsgi e imparare ciò che Graham Dumpleton ci consiglia.

0

Ho appena trascorso alcune ore a risolvere questo problema e la mia correzione era SELinux vietava l'accesso alla mia cartella /django/.

Per verificare se SEStatus sta bloccando l'accesso, visualizzare il registro in /var/log/audit/audit.log

La mia soluzione era semplice:

restorecon -R /var/www/django/