WSGI + django 将导入返回为 NoneType
我有一个应用程序在作为 ./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 ##
返回:
没有属性“debug”
“NoneType”对象在logging.debug(“Drawing %s”行中 ) categories" % draw)
注释 out 会导致
'NoneType' 对象在其下面的行没有属性 'objects'
,等等。一切都肯定会被导入,并且在开发服务器下运行良好。
我的 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()
有什么想法吗?
I have an application that works absolutely fine when run as ./manage.py runserver (or even runserver_plus), but when I deploy it to an apache2+wsgi instance, it breaks. The first model it tries to import (UserProfile) it appears to have imported the requested modules as NoneType.
So, a model like this (this is not exact code, it's not something I can paste onto a public site right now):
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 ##
Returns:
'NoneType' object has no attribute 'debug'
at the line logging.debug("Drawing %s categories" % draw)
Commenting that out results in getting
'NoneType' object has no attribute 'objects'
at the line below it instead, and so on. Everything's definitely being imported, and it works fine under the dev server.
My WSGI file is:
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()
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了。
不确定这是否是某个错误,但最终导致使用 django 的用户配置文件内容以及在 models.py 文件中包含管理模型信息时出现问题。一旦我将所有内容移至其自己的 admin.py 文件中,一切就正常了。
仍然不确定到底是什么原因造成的,但这就是解决方案。
(通过 http://osdir.com/ml/DjangoUsers/2009-07 达成的解决方案/msg00090.html 及其回复)
Solved it.
Not sure if it's a bug in something, but it ended up being an issue with using django's user profile stuff and having Admin model information in the models.py file. Once I moved all that into its own admin.py file, everything worked.
Still not sure what causes it exactly, but that's the solution.
(Solution reached via http://osdir.com/ml/DjangoUsers/2009-07/msg00090.html and its reply)