Upgrading to Django 5.2

by mark | 30 Apr 2025, 7:32 a.m.

Having migrated to Django 4.0 a while back, time for another upgrade to the latest 5.2 and I also did Python to 3.13 at the same time. Neat. 

Main headaches: 

Logging out now has to be done via POST. This has to do with some kind of attack mitigation. Whatever. Implementing this wasn't too bad really. Where I had unit tests for logging out I had to change the method from  response = self.client.get(reverse('logout')) to  response = self.client.post(reverse('logout')); similarly the base template had to be updated so the logout link was no longer just a simple anchor but a form submission. In the template remove:

            <a class="dropdown-item" href="{% url 'logout' %}">Log Out</a>

and replace with 
             <form method="post" action="{% url 'logout' %}" 
               style="display:inline;">
               {% csrf_token %}
               <button type="submit" class="dropdown-item"
                 style="display:inline; cursor:pointer;">Logout</button>
             </form>

Google deprecated their new url notification service, so the thing which pinged that had to be removed. I think I broke the IndexNow! equivalent too but oh well 

Timezone handling has been "improved" in Django. You now need to import pytz and replace references to timezones with pytz equivalents. Not very hard: a few tzinfo=utc became tzinfo=pytz.UTC, mostly in migrations 

The captcha module had been deprecated too, so I had to replace it with django_recaptcha in the installed apps in the settings and update a couple of forms to refer to the new module. 

Apart from that there weren't any big headaches although getting pip to behave with the versions was a pig. Update more often... 

 

Comment: 1
mark | 30 Apr 2025, 7:34 a.m.:

Turns out I did not in fact break IndexNow. Hooray.

Back to all articles