Random 500 error in Python Django Project

I have a project on the Starter plan (at $7/month == 512 MB RAM, 0.5 CPU) using PostgreSQL at the Basic-256mb plan, with 1 GB disk.
These resources are currently more than enough.

I have setup my django project such that when a customer visits:
/products/1205, the server looks for a valid URL, but doesnt find one, then it looks further, and in short, auto sends a Permanently moved response and redirects to
/products/1205/ (this is the actual URL, because it found a valid URL by adding a slash at the end)
This is done by default from django.

Now, when I run my production environment (or my development environment), I get no errors when visiting the wrong URL “/products/1205”, it correctly redirects to “/products/1205/”
BUT
after approximately 12-18 hrs from when I do the latest deploy, a weird error occurs:
visiting the URL “/products/1205” gives me a 500 Server error. The auto-error email logs Django automatically sends to me on errors like these are generally very detailed, entailing the exact place where the error occurs. In this case, there was NO traceback for these errors where Appending a slash results in a valid url.

Report at /products/mb-19
Internal Server Error: /products/mb-19
Request Method:	GET
Request URL:	https://hitecbearings.com/products/mb-19
Django Version:	5.0.8
Exception Location:	, line , in
Python Executable:	/opt/render/project/src/.venv/bin/python
Python Version:	3.10.12
Python Path:	
['/opt/render/project/src',
 '/opt/render/project/python/Python-3.10.12/lib/python310.zip',
 '/opt/render/project/python/Python-3.10.12/lib/python3.10',
 '/opt/render/project/python/Python-3.10.12/lib/python3.10/lib-dynload',
 '/opt/render/project/src/.venv/lib/python3.10/site-packages']
Server time:	Fri, 11 Jul 2025 00:35:19 +0000
Traceback
None
Request information
USER
AnonymousUser

GET
No GET data

POST
No POST data

FILES
No FILES data

COOKIES
No cookie data

As can be seen, the EXCEPTION LOCATION is empty etc.

I am using a custom 404 html template (if that’s relevant)

{% extends "partials/base.html" %}
{% load static i18n host_tags %}

{% block title %}404{{ block.super }}{% endblock title %}

{% block body %}
<div class="container-narrow" id="404-page-container">
  <h1 class="display-2 fw-semibold text-center">404</h1>
  <p class="my-3 text-center fs-5">{% trans "Oooops. Page not found." %}</p>
  <p class="my-3 text-center fs-5">{% trans "If you think this is wrong, consider contacting us" %}<a href="{% url 'home:contact_us' %}"> {% trans "here" %}</a></p>
</div>
{% endblock body %}

The 404.html template doesn’t have any issues and correctly displays the template wherever it should. The template base.html which 404.html extends has some variables which are populated from some custom context_processors.

Everything works fine for the development environment, and also for the first few hours in the production environment, as I highlighted above. Then I get this 500 error for seemingly no reason.

I am not sure if this is a render issue, or a django issue, I am posting here because the Django configuration seems correct, otherwise why would it work for the first few hours on depoyment?

I have tried clearing build cache & deploying, restarting the service, restarting the database, but the error is still there.

Please highlight the issue, is there any auto-caching mechanisms etc. which could give rise to this issue, that render automatically does for my registered plans/services.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.