注册0.8 alpha激活问题

发布于 2024-10-10 00:58:47 字数 3146 浏览 0 评论 0原文

出现以下错误:

Exception Type: TypeError at /accounts/account/activate/success/
Exception Value: activate() takes at least 2 non-keyword arguments (1 given)

我的视图:

def activate(request, backend,
             template_name='registration/activation_complete.html',
             success_url=None, extra_context=None, **kwargs):
        backend = get_backend(backend)
    account = backend.activate(request, **kwargs)

    if account:
        if success_url is None:
            to, args, kwargs = backend.post_activation_redirect(request, account)
            return redirect(to, *args, **kwargs)
        else:
            return redirect(success_url)

    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    return render_to_response(template_name,
                              kwargs,
                              context_instance=context)

我的网址:

urlpatterns = patterns('',
                       url(r'^activate/complete/$',
                           direct_to_template,
                           { 'template': 'registration/activation_complete.html' },
                           name='registration_activation_complete'),
                       # Activation keys get matched by \w+ instead of the more specific
                       # [a-fA-F0-9]{40} because a bad activation key should still get to the view;
                       # that way it can return a sensible "invalid key" message instead of a
                       # confusing 404.
                       url(r'^activate/(?P<activation_key>\w+)/$',
                           activate,
                           { 'backend': 'registration.backends.default.DefaultBackend' },
                           name='registration_activate'),
                       url(r'^register/$',
                           register,
                           { 'backend': 'registration.backends.default.DefaultBackend' },
                           name='registration_register'),
                       url(r'^register/complete/$',
                           direct_to_template,
                           { 'template': 'registration/registration_complete.html' },
                           name='registration_complete'),
                       url(r'^register/closed/$',
                           direct_to_template,
                           { 'template': 'registration/registration_closed.html' },
                           name='registration_disallowed'),
                       (r'', include('registration.auth_urls')),
                       url(r'^account/activate/(?P<activation_key>\w+)/$', 'registration.views.activate', {'success_url': 'account/activate/success/'}, name='registration_activate2'),
                        url(r'^account/activate/success/$', direct_to_template, {'template': 'registration/activation_complete.html'}, name='registration_activation_complete'),

                       )

我做错了什么?

谢谢!

Got the following error:

Exception Type: TypeError at /accounts/account/activate/success/
Exception Value: activate() takes at least 2 non-keyword arguments (1 given)

My view:

def activate(request, backend,
             template_name='registration/activation_complete.html',
             success_url=None, extra_context=None, **kwargs):
        backend = get_backend(backend)
    account = backend.activate(request, **kwargs)

    if account:
        if success_url is None:
            to, args, kwargs = backend.post_activation_redirect(request, account)
            return redirect(to, *args, **kwargs)
        else:
            return redirect(success_url)

    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value

    return render_to_response(template_name,
                              kwargs,
                              context_instance=context)

My url:

urlpatterns = patterns('',
                       url(r'^activate/complete/

What do I do wrong?

Thanks!

, direct_to_template, { 'template': 'registration/activation_complete.html' }, name='registration_activation_complete'), # Activation keys get matched by \w+ instead of the more specific # [a-fA-F0-9]{40} because a bad activation key should still get to the view; # that way it can return a sensible "invalid key" message instead of a # confusing 404. url(r'^activate/(?P<activation_key>\w+)/

What do I do wrong?

Thanks!

, activate, { 'backend': 'registration.backends.default.DefaultBackend' }, name='registration_activate'), url(r'^register/

What do I do wrong?

Thanks!

, register, { 'backend': 'registration.backends.default.DefaultBackend' }, name='registration_register'), url(r'^register/complete/

What do I do wrong?

Thanks!

, direct_to_template, { 'template': 'registration/registration_complete.html' }, name='registration_complete'), url(r'^register/closed/

What do I do wrong?

Thanks!

, direct_to_template, { 'template': 'registration/registration_closed.html' }, name='registration_disallowed'), (r'', include('registration.auth_urls')), url(r'^account/activate/(?P<activation_key>\w+)/

What do I do wrong?

Thanks!

, 'registration.views.activate', {'success_url': 'account/activate/success/'}, name='registration_activate2'), url(r'^account/activate/success/

What do I do wrong?

Thanks!

, direct_to_template, {'template': 'registration/activation_complete.html'}, name='registration_activation_complete'), )

What do I do wrong?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九公里浅绿 2024-10-17 00:58:47

URL /accounts/account/activate/success/'registration.views.activate' 的 URLconf 匹配(倒数第二个),因为 success 匹配 \w+。将真正的 success URL(最后一个)移至此 URL 之上,以便首先匹配它。

The URL /accounts/account/activate/success/ matches the URLconf for 'registration.views.activate' (second from the end), because success matches \w+. Move the real success URL (the final one) above this one, so that it is matched first.

猫性小仙女 2024-10-17 00:58:47

好的,现在可以正常工作了,但是当 activate_complete.html 出现时,仍然出现一条消息,表明激活链接不起作用,尽管用户已在数据库中激活!

出了什么问题?

/猎人

Okay, this is working now, but when activation_complete.html is coming up there ist still a message coming up that the activation link didn't work, although the user is activated in the database!

What is going wrong?

/craphunter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文