Question

I am new to Django and I included django-registration to my project.

It works great except that when a user click on the activation link, his accounts is activated but the user is redirected to a template that says otherwise.

Here is the urls.py part :

urlpatterns = patterns('',
    url(r'^activate/complete/$',
        direct_to_template,
        {'template': 'registration/activation_complete.html'},
        name='registration_activation_complete'),
    url(r'^activate/(?P<activation_key>\w+)/$',
        activate,
        {'backend': 'registration.backends.default.DefaultBackend'},
        name='registration_activate'),

Here is the view part :

def activate(request, backend,
         template_name='registration/activate.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)

The line :

backend.post_activation_redirect 

returns registration_activation_complete

And here is the template :

{% extends "base.html" %}
{% load i18n %}

{% block content %}

{% if account %}

<p>{% trans "Account successfully activated" %}</p>

<p><a href="{% url auth_login %}">{% trans "Log in" %}</a></p>

{% else %}

<p>{% trans "Account activation failed" %}</p>

{% endif %}

{% endblock %}

What I suspect is that it creates the account then gets redirected to another url thanks to the line :

return redirect(to, *args, **kwargs)

Then it calls the generic views direct_to_template but at this moment the variable account does not exist anymore since it was destroyed after the redirection (that's my guess).

I would like to send the account variable to the second view but did not manage to do it.

Thank you for your help with this problem.

Was it helpful?

Solution

The template has a conditional, it checks for the account variable, which is not set. Just remove the conditional and error message and you should be good to go. In django-registration 0.8, that variable is never set for the templates.

Here is a sample Activation Complete Template.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top