Fix logout 405 — Django's LogoutView only accepts POST

The sidebar's "Log out" was a plain <a href> GET link. Django 5's
LogoutView stopped accepting GET (CSRF hardening — a bare link or even an
<img> tag could otherwise log someone out), so clicking it 405'd instead
of logging out. Changed it to a POST form, matching every other
state-changing action in the sidebar/app (unsubscribe, delete tag, etc.).

Extended .sidebar-top-nav's styling to cover a <button> the same as an
<a>, so the form-submit button looks identical to the other nav items.

No existing test exercised logout at all — added one for the POST case
and one confirming GET now correctly 405s, then verified end-to-end
against the running dev server (login, POST /logout/, confirm the session
is gone).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-30 22:01:06 -06:00
1 parent b08a78e747
commit 1a8ae95db0
3 files changed
+38 -3

No files matched your search

+6 -1
View File
@@ -75,7 +75,12 @@
<li><a href="{% url 'articles:tag_list' %}">Manage tags</a></li>
<li><a href="{% url 'rules:rule_list' %}">Rules</a></li>
{% if request.user.is_staff %}<li><a href="{% url 'core:dashboard' %}">Dashboard</a></li>{% endif %}
<li><a href="{% url 'accounts:logout' %}">Log out</a></li>
<li>
<form method="post" action="{% url 'accounts:logout' %}">
{% csrf_token %}
<button type="submit">Log out</button>
</form>
</li>
</ul>
<div class="theme-switcher" role="group" aria-label="Theme">