我在使用 django + wsgi 时遇到了这个问题,我不明白为什么。当我访问使用 apache2 + wsgi 运行的本地网站时,出现以下错误:
ImportError at /
No module named models
但是当我使用开发服务器运行时,一切正常:python manage.py runserver 0:8080
。
我的 wsgi.py :
import os, sys
sys.path.append('/var/www/reader')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "reader.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我的模型.py
from django.db import models
from django.contrib.auth.models import User
class Feed(models.Model):
display_name = models.CharField(max_length=255)
link_feed = models.CharField(max_length=255)
user = models.ForeignKey(User)
我的views.py抛出错误:
from django.shortcuts import render
from reader.models import Feed
def index(request):
feeds_list = Feed.objects.all()
context = {'feeds_list': feeds_list}
return render(request, 'home/index.html', context)
在我的设置中:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'reader', <-- this is my app
)
我在 Python 2.7.4 和 django 1.5.1 下运行。
有人可以向我解释为什么吗?
更新 1:
jeremy@dev:/var/www/reader$ tree .
.
├── manage.py
└── reader
├── __init__.py
├── models.py
├── reader.settings
├── settings.py
├── static
│ ├── images
│ ├── scripts
│ │ └── script.js
│ └── styles
│ └── style.css
├── templates
│ ├── base.html
│ ├── home
│ │ └── index.html
│ └── subscription
│ └── add.html
├── urls.py
├── views.py
└── wsgi.py
8 directories, 13 files