簡體   English   中英

Django-python3.4 virtualenv-Apache

[英]Django - python3.4 virtualenv - apache

我有一個Django應用程序,我一直在使用manage.py runserver進行調試。

我現在嘗試與apache / mod_wsgi一起使用。

當我嘗試打開主頁時,收到500錯誤。 日志文件在functools.py中顯示語法錯誤。

mod_wsgi (pid=28016): Target WSGI script '/home/username/projects/django/testing/testing/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=28016): Exception occurred processing WSGI script '/home/username/projects/django/testing/testing/wsgi.py'.
Traceback (most recent call last):
File "/home/username/projects/django/testing/testing/wsgi.py", line 12, in <module>
  from django.core.wsgi import get_wsgi_application
File "/home/username/.virtualenvs/testing/lib/python3.4/site-packages/django/__init__.py", line 1, in <module>
  from django.utils.version import get_version
File "/home/username/.virtualenvs/testing/lib/python3.4/site-packages/django/utils/version.py", line 7, in <module>
  from django.utils.lru_cache import lru_cache
File "/home/username/.virtualenvs/testing/lib/python3.4/site-packages/django/utils/lru_cache.py", line 2, in <module>
  from functools import lru_cache
File "/home/username/.virtualenvs/testing/lib/python3.4/functools.py", line 291
  cls_or_self, *rest = args
               ^
SyntaxError: invalid syntax

據我所知,這是有效的python3.4語法。 所以我不能完全確定是否已正確配置WSGI以使用我的virtualenv。

#testing.conf
<VirtualHost *:80>
    WSGIDaemonProcess django.testing.username.vni user=username group=username python-path=/home/username/.virtualenvs/testing/lib/python3.4/site-packages:/home/username/.virtualenvs/testing/lib/python3.4:/home/username/.virtualenvs/testing
    WSGIProcessGroup django.testing.username.vni

    WSGIScriptAlias / /home/username/projects/django/testing/testing/wsgi.py

    ServerAdmin username@webserver.com
    ServerName django.testing
    ServerAlias www.django.testing

    Alias /static/ /home/username/projects/django/testing/static/

    <Directory />
        AllowOverride None
        Options -Indexes
    </Directory>

    <Directory /home/username/projects/django/testing/testing>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    ErrorLog /var/log/apache2/django.testing.log
    LogLevel warn

</VirtualHost>

我想我上面可能有問題的python-path。

#wsgi.py
import os

from django.core.wsgi import get_wsgi_application

import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

application = get_wsgi_application()

我不確定是否已正確處理sys.path.append()或DJANGO_SETTINGS_MODULE。 他們就是要解決我遇到的其他一些錯誤。

正如Daniel Roseman所建議的那樣,問題是我為python3.4使用了錯誤的mod_wsgi版本。 我刪除了libapache2-mod-wsgi並安裝了libapache2-mod-wsgi-py3。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM