Django装饰器生成SiteProfileNotAvailable错误 [英] Django decorator generates SiteProfileNotAvailable error

查看:121
本文介绍了Django装饰器生成SiteProfileNotAvailable错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里学习Python(2.6)和Django(1.2)的新手。请考虑以下我想在方法上使用的修饰符,以及@login_required,如果用户尝试执行需要提供最少信息配置文件的操作,则会将其重定向到配置文件完成URL。

Newbie to Python (2.6) and Django (1.2) here, learning the ropes. Consider the following decorator that I want to use on methods, along with @login_required, that redirects users to a profile completion url if they try and do something that requires a "minimum information supplied" profile.

使用模式应为:

@login_required
@min_profile_required
def my_view(request):
    # do whatever.

我当前对min_profile_required装饰器的定义如下:

My current defintion of the min_profile_required decorator is as follows:

def min_profile_required(decorated_view):
    @wraps(decorated_view)
    def redirector(request, *args, **kwargs):
        if ProfileHelper.is_min_profile_complete(request.user):
            return decorated_view(request, *args, **kwargs) 
        return HttpResponseRedirect(PROFILE_COMPLETION_URL)
    return redirector

对我来说,这有点像Python 101,但Django一点都不喜欢。生成以下错误

To me, this feels like a bit of Python 101, but Django doesn't like it at all. The following error is generated

SiteProfileNotAvailable at ...
app_label and model_name should be separated by a dot in the AUTH_PROFILE_MODULE setting

装饰器是帐户应用程序的一部分,因此AUTH_PROFILE_MODULE设置不属于装饰器定义属于(或用于)装饰器的应用程序。

The decorator is part of an "accounts" application, so the AUTH_PROFILE_MODULE setting isn't part of the app the decorator definition belongs to (or is used on).

我觉得这应该很容易,所以我肯定缺少一些细微的东西,也许与

I feel this should be easy, so there must be something subtle I am missing, maybe related to 'chaining' decorators?

非常感谢您提供协助。

更新:这是我的个人资料设置。

Update: Here is my profile setting.

AUTH_PROFILE_MODULE = 'cta.account.models.user_profile.UserProfile'

下面提供的答案:我的个人资料模型配置错误,应该已经

Answer supplied below: My profile model was incorrectly configured, it should have been

AUTH_PROFILE_MODULE = 'account.UserProfile'


推荐答案

在我看来,您的settings.py文件中的配置文件设置有误。它看起来应该像这样:< app>。< model> ,而这正是 django 所抱怨的。检查您的设置。

For me it seems, that you have wrong profile setting in your settings.py. It should look like this: <app>.<model> and that's exactly what django is complaining about. Check out your settings.

这篇关于Django装饰器生成SiteProfileNotAvailable错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆