我使用的是Ubuntu 14.04,Apache2和mod_wsgi-4.5.3,Django 1.10b1,我是wsgi的新手。 每次我尝试将txt文件上传到我的网站时,我都会在mod_wsgi错误日志中收到以下错误: [Thu Jul 07 19:39:20.261989 2016] [wsgi:error] [pid 1233:tid 140054790215424] txt
网页显示“服务器错误500”
这是我的wsgi.py
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/django/myvirtualenvironment/lib/python3.4/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/django/myvirtualenvironment/DoTanalyzer')
sys.path.append('/home/django/myvirtualenvironment/DoTanalyzer/TextAnalyzer')
os.environ['DJANGO_SETTINGS_MODULE'] = 'TextAnalyzer.settings'
# Activate your virtual env
activate_env=os.path.expanduser("/home/django/myvirtualenvironment/bin/activate_this.py")
# execfile(activate_env, dict(__file__=activate_env))
exec(compile(open(activate_env, "rb").read(), activate_env, 'exec'), dict(__file__activate_env))
import django.core.handlers.wsgi
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/django/myvirtualenvironment/DoTanalyzer')
sys.path.append('/home/django/myvirtualenvironment/DoTanalyzer/TextAnalyzer')
os.environ['DJANGO_SETTINGS_MODULE'] = 'TextAnalyzer.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
这是我在views.py中保存文件的方法
def upload_file(request):
if not request.user.is_authenticated():
return render(request, 'analyze/login_user.html')
else:
form = FileForm(request.POST or None, request.FILES or None)
if form.is_valid():
file = form.save(commit=False)
file.user = request.user
file.file = request.FILES['file']
file.file_name = request.FILES['file'].name
file_type = file.file.url.split('.')[-1]
print(file_type)
if check_file_type(file_type):
file.save()
return render(request, 'analyze/results.html', {'results': results})
else:
return render(request, 'analyze/upload_file.html', {'form': form, 'error_message': '.txt only'})
else:
return render(request, 'analyze/upload_file.html', {'form': form})