开发者

Django decorator generates SiteProfileNotAvailable error

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.

The usage pattern is intended to be:

@login_required
@min_profile_required
def my_view(request):
    #开发者_StackOverflow do whatever.

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

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

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?

Any assistance much appreciated.

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'


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜