简体   繁体   中英

Django 1.4 with apache2

I have problem with Django 1.4 and apache2. I have following code:

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

It raise SiteProfileNotAvailable error, below if not Profile: statement. This means models.get_model is failed get profile model. Same code in my local test environment works greatly. What can go wrong?

Edit: my AUTH_PROFILE_MODULE is as follows in settings.py file.

AUTH_PROFILE_MODULE = 'profile.Profile'

Perhaps you should change your test like this (use a variable already instantiated for testing in the if statement). Your testing for a variable False and None is evaluating as False in that test:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM