2016-05-16 17 views
0

私はDjangoプロジェクトをApacheにデプロイしようとしています。しかし、私はエラー500responseを得ています。また、ログには、Djangoがない情報が表示されます。私はvirtualenvを使ってこのプロジェクトを実行しています。私がDjangoプロジェクトを展開しようとするのは初めてです。そして私の経験から、私はおそらく単純なことをいくつか見逃していることを知っています。私はこのサイトで解決策を探していましたが、以前のバージョンのDjangoとPython用です。彼らは私のために働かない。Django 1.9 Apacheエラーのインポートdjango.core.handlers.wsgi ImportError: 'django'というモジュールがありません

これは私wsgi.py

WSGIScriptAlias//home/mariusz/Dokumenty/Projekty/zalien/zalien/wsgi.py 
WSGIDaemonProcess localhost python-path=/home/mariusz/Dokumenty/Projekty/zalien:/home/mariusz/Dokumenty/Projekt/envy/lib/python3.5/site-packages 

<Directory /home/mariusz/Dokumenty/Projekty/zalien/zalien> 
<Files wsgi.py> 
Require all granted 
</Files> 
</Directory> 

である。これは私のApacheのTest.confをさ

import os import sys import site from django.core.wsgi import get_wsgi_application application = django.core.handlers.wsgi.WSGIHandler() # Add the site-packages of the chosen virtualenv to work with site.addsitedir('/home/mariusz/Dokumenty/Projekty/envy/local/lib/python3.5/site-packages') # Add the app's directory to the PYTHONPATH sys.path.append('/home/mariusz/Dokumenty/Projekty/zalien') sys.path.append('/home/mariusz/Dokumenty/Projekty/zalien/zalien') os.environ['DJANGO_SETTINGS_MODULE'] = 'zalien.settings' # Activate your virtual env activate_env=os.path.expanduser("/home/mariusz/Dokumenty/Projekty/envy/bin/activate_this.py") exec(activate_env, dict(__file__=activate_env)) 

エラーログ

[Mon May 16 09:44:28.368084 2016] [wsgi:error] [pid 7418:tid 139640747427584] mod_wsgi (pid=7418): Call to 'site.addsitedir()' failed for '(null)', stopping. 
[Mon May 16 09:44:28.368132 2016] [wsgi:error] [pid 7418:tid 139640747427584] mod_wsgi (pid=7418): Call to 'site.addsitedir()' failed for '/home/mariusz/Dokumenty/Projekty/zalien/'. 
[Mon May 16 09:44:28.369458 2016] [wsgi:error] [pid 7418:tid 139640747427584] [client 127.0.0.1:37494] mod_wsgi (pid=7418): Target WSGI script '/home/mariusz/Dokumenty/Projekty/zalien/zalien/wsgi.py' cannot be loaded as Python module. 
[Mon May 16 09:44:28.369493 2016] [wsgi:error] [pid 7418:tid 139640747427584] [client 127.0.0.1:37494] mod_wsgi (pid=7418): Exception occurred processing WSGI script '/home/mariusz/Dokumenty/Projekty/zalien/zalien/wsgi.py'. 
[Mon May 16 09:44:28.369724 2016] [wsgi:error] [pid 7418:tid 139640747427584] [client 127.0.0.1:37494] Traceback (most recent call last): 
[Mon May 16 09:44:28.369752 2016] [wsgi:error] [pid 7418:tid 139640747427584] [client 127.0.0.1:37494] File "/home/mariusz/Dokumenty/Projekty/zalien/zalien/wsgi.py", line 23, in <module> 
[Mon May 16 09:44:28.369758 2016] [wsgi:error] [pid 7418:tid 139640747427584] [client 127.0.0.1:37494]  from django.core.wsgi import get_wsgi_application 
[Mon May 16 09:44:28.369781 2016] [wsgi:error] [pid 7418:tid 139640747427584] [client 127.0.0.1:37494] ImportError: No module named 'django' 

権限

-rw-rw-r-- 1 mariusz www-data 295 May 9 14:50 app.json 
-rw-rw-r-- 1 mariusz www-data 51200 May 13 09:53 db.sqlite3 
drwxrwxr-x 4 mariusz www-data 4096 May 13 10:06 games 
-rwxrwxr-x 1 mariusz www-data 249 May 9 14:50 manage.py 
drwxrwxr-x 4 mariusz www-data 4096 May 13 10:06 portal 
-rw-rw-r-- 1 mariusz www-data 39 May 9 14:50 Procfile 
-rw-rw-r-- 1 mariusz www-data 45 May 9 14:50 Procfile.windows 
-rw-rw-r-- 1 mariusz www-data 1368 May 9 14:50 README.md 
-rw-rw-r-- 1 mariusz www-data 298 May 9 14:50 requirements.txt 
-rw-rw-r-- 1 mariusz www-data 13 May 9 14:50 runtime.txt 
drwxrwxr-x 5 mariusz www-data 4096 May 9 14:50 static 
drwxrwxr-x 4 mariusz www-data 4096 May 9 14:50 templates 
drwxrwxr-x 4 mariusz www-data 4096 May 13 10:06 userprofile 
drwxrwxr-x 3 mariusz www-data 4096 May 16 11:50 zalien 
+0

可能な重複します(http:/ /stackoverflow.com/questions/38284814/django-apache-configuration-with-wsgidaemonprocess-not-working) – e4c5

答えて

0

私はジャンゴで、いくつかのApacheサーバを持って、私はそれらを設定するときには痛みでした。だから、静的ファイルと最小限の作業構成は次のとおりです。また、あなたはあなたのDjangoのプロジェクトであなたのwsgi.pyファイルを

WSGIPythonPath /home/mariusz/Dokumenty/Projekty/zalien 

<VirtualHost *:80> 
    WSGIScriptAlias//home/mariusz/Dokumenty/Projekty/zalien/zalien/wsgi.py 

    <Directory /home/mariusz/Dokumenty/Projekty/zalien/zalien> 
     <Files wsgi.py> 
      Require all granted 
     </Files> 
    </Directory> 

    # Django static files, here you must specify your own path's 
    Alias /static/ /var/www/djangointra/static/ 
    <Directory "/var/www/djangointra/static"> 
     Require all granted 
    </Directory> 
</VirtualHost> 

変更すべきではありません。 Webサーバーを起動するには、Apacheの設定で十分です。

EDIT:wsgi.py

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

import os 

from django.core.wsgi import get_wsgi_application 

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

application = get_wsgi_application() 
+0

デフォルトのwsgi.pyファイルを貼り付けることができます。 鉱山は( アプリケーション= get_wsgi_applicationをDjangoWhiteNoise whitenoise.djangoインポートからdjango.core.wsgiインポートget_wsgi_application から 'インポートOS os.environ.setdefault( "DJANGO_SETTINGS_MODULE"、 "zalien.settings") ように見えます) アプリケーション= DjangoWhiteNoise(アプリケーション) そして、私はまだこの同じエラーを受け取ります –

+0

@MariuszŁaszewskiyes :)。 EDITを見てください。 – valex

+0

上記と同じようにまだ同じです。 –

0

決して遅すぎます。これが他人を助けることでしょう。私は同じエラーがあり、それは2つの変更によって解決されます。以下は作業設定です。私は

Test.confをDjangoの1.10、Pythonの3.5とApache 2.4

wsgi.pi

import os, sys, site 

from django.core.wsgi import get_wsgi_application 


site.addsitedir("/home/mariusz/Dokumenty/Projekt/envy/lib/python3.5/site-packages") 

sys.path.append("/home/mariusz/Dokumenty/Projekty/zalien") 
sys.path.append("/home/mariusz/Dokumenty/Projekty/zalien/zalien") 

activate_this = "/home/mariusz/Dokumenty/Projekty/envy/bin/activate_this.py" 
with open(activate_this) as f: 
    code = compile(f.read(), activate_this, "exec") 
    exec(code, dict(__file__=activate_this)) 

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

application = get_wsgi_application() 

にApacheを持っていた

<VirtualHost *:80> 
     WSGIDaemonProcess zalien processes=2 threads=12 python-home=/home/mariusz/Dokumenty/Projekt/envy/ python-path=/home/mariusz/Dokumenty/Projekty/zalien:/home/mariusz/Dokumenty/Projekt/envy//lib/python3.5/site-packages 
     WSGIProcessGroup zalien 
     WSGIScriptAlias//home/mariusz/Dokumenty/Projekty/zalien/wsgi.py process-group=zalien 
     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

     Alias /static/ /var/www/html/static/ 
     <Directory /var/www/html/static/> 
      Require all granted 
     </Directory> 

     <Directory /home/mariusz/Dokumenty/Projekty/zalien> 
      <Files wsgi.py> 
       Require all granted 
      </Files> 
     </Directory> 
</VirtualHost> 
[WSGIDaemonProcessが機能していないとジャンゴApacheの設定]の
関連する問題