У меня есть приложение, которое отлично работает при запуске в качестве ./manage.py runserver (или даже runserver_plus), но когда я развертываю его на экземпляре apache2+wsgi, оно ломается. Первая модель, которую он пытается импортировать (UserProfile), похоже, импортировала запрошенные модули как NoneType.
Итак, такая модель (это не точный код, я не могу прямо сейчас вставить его на общедоступный сайт):
from django.db import models
from django.contrib.auth.models import User
from BlogEngine.categorisation.models import Category
from django.db.models.signals import post_save
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext as _
import logging
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
category = models.ManyToManyField(Category, blank=True, related_name="category")
def __unicode__(self):
return "Profile for %s" % user.username
def update_categories(self):
"""Updates the categories list"""
pull_more = self.category_selection_max - self.category.count()
if pull_more == 0:
return self.category_selection
logging.debug("Drawing %s categories" % draw)
categories = Category.objects.filter(
is_live=True
).order_by("?")[:pull_more]
## More code under here ##
Возвращает:
Объект «NoneType» не имеет атрибута «отладка»
в строке logging.debug("Отрисовка категорий %s" % draw)
Комментирование этого приводит к получению
Объект «NoneType» не имеет атрибута «объекты»
вместо этого на строке под ним и так далее. Все определенно импортируется и отлично работает под сервером разработки.
Мой файл WSGI:
import sys
import site
import os
vepath = '/home/aquarion/newsite/django/virtualenv/lib/python2.6/site-packages'
#prev_sys_path = list(sys.path)
## add the site-packages of our virtualenv as a site dir
site.addsitedir(vepath)
## add the app's directory to the PYTHONPATH
sys.path.append('/home/aquarion/newsite/django/')
# import from down here to pull in possible virtualenv django install
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'BlogEngine.settings'
application = WSGIHandler()
Любые идеи?
sys.modules
? - person Ignacio Vazquez-Abrams   schedule 19.03.2011