0

我对 Django 1.4 和 apache2 有疑问。我有以下代码:

from django.db import models
from django.contrib.auth.models import User, SiteProfileNotAvailable
from django.conf import settings

....
*.... so many includes....*
.....

try:
    app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
    Profile = models.get_model(app_label, model_name)
except (ImportError, ImproperlyConfigured):
    raise SiteProfileNotAvailable

if not Profile:
    raise SiteProfileNotAvailable

它会引发 SiteProfileNotAvailable 错误,在 if not Profile: 语句下方。这意味着 models.get_model 获取配置文件模型失败。我本地测试环境中的相同代码效果很好。会出什么问题?

编辑:我的 AUTH_PROFILE_MODULE 在 settings.py 文件中如下所示。

AUTH_PROFILE_MODULE = 'profile.Profile'
4

2 回答 2

0

我将配置文件模型重命名为 uprofile(现在它就像 uprofile.uprofile),一切正常。

于 2012-12-28T04:52:40.210 回答
0

也许您应该像这样更改您的测试(在 if 语句中使用已经实例化的变量进行测试)。您对变量的测试False并在该测试中None进行评估False

model_found = False

try:
    app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
    Profile = models.get_model(app_label, model_name)
    model_found = True
except (ImportError, ImproperlyConfigured):
    raise SiteProfileNotAvailable

if not model_found:
    raise SiteProfileNotAvailable
于 2012-12-12T20:00:11.050 回答