templates: fix account activation for django-registration 5
PATCH 1/1 templates: fix account activation for django-registration 5
Since the Django 5.2 upgrade (23fdeac) pulled in django-registration 5.x, sending an activation email fails with NoReverseMatch: the template passed the activation key as a URL argument, but the "django_registration_activate" URL now takes it as the activation_key query parameter. New registrations, and users changing their email address on the profile page, were left deactivated with no email sent.
The activation view is now a form that POSTs the key back and renders django_registration/activation_form.html, so replace the old activate.html and activation_failed.html templates with it.
AI-Generated: Claude Opus 5.5
--- templates/django_registration/activate.html | 18 ------- .../activation_email_body.txt | 2 +- .../activation_failed.html | 13 ----- .../django_registration/activation_form.html | 21 ++++++++ tests/test_account_activation.py | 52 +++++++++++++++++++ 5 files changed, 74 insertions(+), 32 deletions(-) delete mode 100644 templates/django_registration/activate.html delete mode 100644 templates/django_registration/activation_failed.html create mode 100644 templates/django_registration/activation_form.html create mode 100644 tests/test_account_activation.py
templates/django_registration/activate.html deleted +0 -18
@@ -1,18 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} - -{% block content %} - -{% if account %} - -<p>{% trans "Account successfully activated" %}</p> - -<p><a href="{% url "login" %}">{% trans "Log in" %}</a></p> - -{% else %} - -<p>{% trans "Account activation failed" %}</p> - -{% endif %} - -{% endblock %}
templates/django_registration/activation_email_body.txt +1 -1
@@ -7,7 +7,7 @@ link is valid for {{ expiration_days }} days. {% endblocktrans %} -http://{{ site.domain }}{% url "django_registration_activate" activation_key %} +http://{{ site.domain }}{% url "django_registration_activate" %}?activation_key={{ activation_key|urlencode }} {% blocktrans %} If you did not make this request, please ignore this message.
templates/django_registration/activation_failed.html deleted +0 -13
@@ -1,13 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} - -{% block content %} - -{% blocktrans %} - -Activation has failed. -<br/> - -{% endblocktrans %} - -{% endblock %}
templates/django_registration/activation_form.html new file +21 -0
@@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% load i18n %} + +{% block content %} + +{% if activation_error %} +<div class="alert alert-danger">{{ activation_error.message }}</div> +{% elif form.errors %} +<div class="alert alert-danger">{% trans "This activation link is invalid or has expired." %}</div> +{% else %} +<p>{% trans "Click the button below to activate your account." %}</p> +<form id="activation_form" method="post" action=""> + {% for field in form %} + <input type="hidden" name="{{ field.html_name }}" value="{{ field.value|default_if_none:'' }}" /> + {% endfor %} + <input type="submit" class="btn btn-default" value="{% trans 'Activate account' %}" /> + {% csrf_token %} +</form> +{% endif %} + +{% endblock %}
tests/test_account_activation.py new file +52 -0
52 lines not on this page · raw message
base-commit: e6040597ae0f614581de241fe78f20e34dae13ac
Signature · 1 line
2.56.0