apache2 / mod_wsgi / django production satchmo导入的NoneType错误

时间:2011-10-27 12:41:24

标签: django apache mod-wsgi production-environment satchmo

我正在努力(非常努力)将我的Django应用程序部署到apache2 / mod_wsgi,但是我遇到的错误只发生在生产环境中。我非常感谢有关下一步该怎么做的任何建议。错误是:

'NoneType' object has no attribute 'objects'

堆栈跟踪指向此功能:

by_site

/ var /webapps/MYAPP/releases/current/apps/product/models.py

"""
Base model used for products.  Stores hierarchical categories
as well as individual product level information which includes
options.
"""
from decimal import Context, Decimal, ROUND_FLOOR
from django import forms
from django.conf import settings
from django.contrib.sites.models import Site
from django.core import urlresolvers
from django.core.cache import cache
from django.db import models
from django.db.models import Q
from django.utils.translation import get_language, ugettext, ugettext_lazy as _
from l10n.utils import moneyfmt, lookup_translation
from livesettings import config_value, SettingNotSet, config_value_safe
from prices import get_product_quantity_price, get_product_quantity_adjustments
from product import active_product_types
from product.prices import PriceAdjustmentCalc
from satchmo_utils import get_flat_list
from satchmo_utils.fields import CurrencyField
from satchmo_utils.thumbnail.field import ImageWithThumbnailField
from satchmo_utils.unique_id import slugify
import config   #This import is required to make sure livesettings picks up the config values
import datetime
import keyedcache
import logging
import operator
import signals

log = logging.getLogger('product.models')

dimension_units = (('cm','cm'), ('in','in'))

weight_units = (('kg','kg'), ('lb','lb'))

DISCOUNT_SHIPPING_CHOICES = (
('NONE', _('None')),
('FREE', _('Free Shipping')),
('FREECHEAP', _('Cheapest shipping option is free')),
('APPLY', _('Apply the discount above to shipping'))
)

SHIP_CLASS_CHOICES = (
('DEFAULT', _('Default')),
('YES', _('Shippable')),
('NO', _('Not Shippable'))
)

STANDARD_COMPARISON_MEASURES = (
#Weight
('g', '100'),
('kg', '1'),
('mg', '100'),
#Volume
('L', '1'),
('ml', '100'),
#Length
('mm', '100'),
('cm', '100'),
('m', '1'),
('inches', '100'),
#Electricity
('W', '1'),
('V', '1'),
#Each / Pack
('other', '1'),
)

def default_dimension_unit():
val = config_value_safe('PRODUCT','MEASUREMENT_SYSTEM', (None, None))[0]
if val == 'metric':
    return 'cm'
else:
    return 'in'

def default_weight_unit():
val = config_value_safe('PRODUCT','MEASUREMENT_SYSTEM', (None, None))[0]
if val == 'metric':
    return 'kg'
else:
    return 'lb'

class CategoryManager(models.Manager):
def active(self):
    return self.filter(is_active=True)

def by_site(self, site=None, **kwargs):
    """Get all categories for this site"""
    if not site:
        site = Site.objects.get_current()                  <<<<<<<< Line causing error... apparently 

    site = site.id

    return self.active().filter(site__id__exact = site, **kwargs)

def get_by_site(self, site=None, **kwargs):
    if not site:
        site = Site.objects.get_current()              
    return self.active().get(site = site, **kwargs)

def root_categories(self, site=None, **kwargs):
    """Get all root categories."""

    if not site:
        site = Site.objects.get_current()

    return self.active().filter(parent__isnull=True, site=site, **kwargs)

def search_by_site(self, keyword, site=None, include_children=False):
    """Search for categories by keyword.
    Note, this does not return a queryset."""

    if not site:
        site = Site.objects.get_current()

    cats = self.active().filter(
        Q(name__icontains=keyword) |
        Q(meta__icontains=keyword) |
        Q(description__icontains=keyword),
        site=site)

    if include_children:
        # get all the children of the categories found
        cats = [cat.get_active_children(include_self=True) for cat in cats]

    # sort properly
    if cats:
        fastsort = [(c.ordering, c.name, c) for c in get_flat_list(cats)]
        fastsort.sort()
        # extract the cat list
        cats = zip(*fastsort)[2]
    return cats

这是抛在satchimo模块中的'产品'。它已在MYAPP / apps中复制和自定义。它在settings.py中安装为'apps.product'。

我的modwsgi文件位于MYAPP / deploy /:

import os
import sys

# redirect sys.stdout to sys.stderr for bad libraries like geopy that uses
# print statements for optional import exceptions.
sys.stdout = sys.stderr

from os.path import abspath, dirname, join
from site import addsitedir

sys.path.insert(0, '/var/webapps/MYAPP/releases/current/apps')
sys.path.insert(0, '/var/webapps/MYAPP/releases/current')
sys.path.insert(0, abspath(join(dirname(__file__), "..", "..")))

from django.conf import settings
os.environ["DJANGO_SETTINGS_MODULE"] = "current.settings"

sys.path.insert(0, join(settings.PINAX_ROOT, "apps"))
sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

其他信息

Django版本:1.3.1 Python版本:2.7.1 Python路径:

['/var/webapps/MYAPP/releases/current/apps',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages/pinax/apps',
 '/var/webapps/MYAPP/releases',
 '/var/webapps/MYAPP/releases/current',
 '/var/webapps/MYAPP/releases/current/apps',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/var/webapps/MYAPP/releases/current/env/lib/python2.7/site-packages',
 '/var/webapps/MYAPPreleases/current/env/lib/python2.7/site-packages/PIL',
 '/usr/local/lib/python2.7/dist-packages/virtualenv-1.6.4-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7']

0 个答案:

没有答案