Django decorator generates SiteProfileNotAvailable error

拜拜、爱过 提交于 2019-12-25 01:08:04

问题


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):
    # 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'

回答1:


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.



来源:https://stackoverflow.com/questions/5071707/django-decorator-generates-siteprofilenotavailable-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!