# square brackets bug

**URL:** <https://forum.djangoproject.com/t/square-brackets-bug/29632>\
**Category:** Mystery Errors\
**Created:** [March 29, 2024, 8:16pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632 "2024-03-29T20:16:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian-atkinson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ian-atkinson/32/20241_2.png) [@ian-atkinson](https://forum.djangoproject.com/u/ian-atkinson)\
**Post date:** [March 29, 2024, 8:16pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/1 "2024-03-29T20:16:15Z")

</div>

Hi,

Have just tried to log a ticket for a bug however the ticket tracker said it was 94% convinced it was spam so wouldn’t take it, um lucky me? Not sure if this is the right place but putting it here instead for someone’s attention.

* * *

Hi,

I’ve come across an issue where my forms are having random sets of empty square braces rendered into them, I can’t find any mention of this other than one StackOverflow post where a guy said he downgraded his python and it went away.

I’m on a Mac running Python 3.12.2 (from python website) and Homebrew Apache 2. Curiously this issue only occurs when viewing sites through Apache/WSGI not when running the test server using Django. However, this does occur both in my own apps as well as the Django admin login page.

I’ve had a look into this and can see that the brackets are getting returned by Django in the form render so this isn’t any spurious typo on my part or some dodgy CSS as far as I can tell.

I made the RenderableMixin function in forms/utils.py write out the code it was returning to a temp file and I can see them in there:

```auto
└─$ cat /tmp/render
<tr>
    <th><label for="id_term">Search Term:</label></th>
    <td>
      []
      <input type="text" name="term" maxlength="25" required id="id_term">

    </td>
  </tr>

```

I’m not sure how to look any deeper down than that as I’m not familiar with the code base. This is happening off the back of a very simple form with nothing weird going on, it’s pretty much as per the official tutorials as I’m just learning this

```auto
{% block content %}
		<form action="{% url 'accounts:search' %}" method="post">
			{% csrf_token %}
			{{ form.as_table }}
			<input type="submit" value="Submit">
		</form>
{% endblock %}

```

```auto
class SearchForm(forms.Form):
	term = forms.CharField(label="Search Term", max_length=25)

def DisplaySearchForm(request):
	if request.method == "POST":
		form = SearchForm(request.POST)
		if form.is_valid():
			return HttpResponseRedirect(reverse("accounts:search_results", kwargs={'term': form.cleaned_data['term']}))
	else:
		form = SearchForm()

	return render(request, "accounts/search.html", {"form": form})

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 29, 2024, 8:22pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/2 "2024-03-29T20:22:40Z")

</div>

What version of Django are you using?

Also when you say:

> [@ian-atkinson](#):
>
> when viewing sites through Apache/WSGI

Are you running your project using `mod_wsgi`, or do you have your Apache configured to proxy the requests through to a `uwsgi` instance?

---

<div class="post-metadata">

**Author:** ![ian-atkinson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ian-atkinson/32/20241_2.png) [@ian-atkinson](https://forum.djangoproject.com/u/ian-atkinson)\
**Post date:** [March 29, 2024, 8:25pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/3 "2024-03-29T20:25:46Z")

</div>

The django is 5.0.3 (says PIP)

`Requirement already satisfied: django in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (5.0.3)`

I set up the Apache with mod\_wsgi yes

`LoadModule wsgi_module /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/mod_wsgi/server/mod_wsgi-py312.cpython-312-darwin.so`

I did some screenshots but it doesn’t seem to want to attach them

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 29, 2024, 8:32pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/4 "2024-03-29T20:32:14Z")

</div>

To try and narrow this down, do you still get the brackets if you render this using `as_div` or `as_p`?

What do you get if you add a `print(form)` immediately before the return statement?

Have you overridden any of the system templates? (Such as `django/forms/table.html`)

---

<div class="post-metadata">

**Author:** ![ian-atkinson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ian-atkinson/32/20241_2.png) [@ian-atkinson](https://forum.djangoproject.com/u/ian-atkinson)\
**Post date:** [March 29, 2024, 8:48pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/5 "2024-03-29T20:48:12Z")

</div>

Yes I’ve tried using the various options (div, table, p, ul) is doesn’t seem to make a difference they just appear within the tags.

Table:

```auto
<div class="row">
	<div class="col-2 col-12-small">
		<form action="/leodis_admin/search/" method="post">
			<input type="hidden" name="csrfmiddlewaretoken" value="LivzmTJw8dI3bbiOByKFaqcQhV3Zv1PLVRTqwgv1Qq5SLFUjgasqvgCzgr2Yn2td">
			<tr>
    <th><label for="id_term">Search Term:</label></th>
    <td>
      []
      <input type="text" name="term" maxlength="25" required id="id_term">
      
      
        
      
    </td>
  </tr>
			<input type="submit" value="Submit">
		</form>
	</div>
</div>

```

as p

```auto
<div class="row">
	<div class="col-2 col-12-small">
		<form action="/leodis_admin/search/" method="post">
			<input type="hidden" name="csrfmiddlewaretoken" value="DwB4W2r3jcebi2tqiDNh7BS4fbFkDxEQN5ZV6pdy1pB0Sw5VXfv2sriNeHEjvyii">
			[]

  []
  <p>
    <label for="id_term">Search Term:</label>
    <input type="text" name="term" maxlength="25" required id="id_term">
    
    
      
    
  </p>
			<input type="submit" value="Submit">
		</form>
	</div>
</div>

```

ul

```auto
<div class="row">
	<div class="col-2 col-12-small">
		<form action="/leodis_admin/search/" method="post">
			<input type="hidden" name="csrfmiddlewaretoken" value="2t8yGhxBymu3r3H8n5yXbFYocZIfXNLYc2wpQEj6gzRS1xjD2HgIwvo7bvHePOpq">
			<li>
    []
    <label for="id_term">Search Term:</label>
    <input type="text" name="term" maxlength="25" required id="id_term">
    
    
      
    
  </li>
			<input type="submit" value="Submit">
		</form>
	</div>
</div>

```

printing the form when running the test server they are not in there in console output:

```auto
Quit the server with CONTROL-C.

<div>
    <label for="id_term">Search Term:</label>

<input type="text" name="term" maxlength="25" required id="id_term">

</div>
[29/Mar/2024 20:40:44] "GET /search/ HTTP/1.1" 200 2461

```

For testing with the apache I had it write the same output to /tmp (not sure how else I’d see it), and they are there:

```auto
┌──(ian@phasma)-[~/code/python/_django]
└─$ cat /tmp/form
[]

  <div>
    <label for="id_term">Search Term:</label>

[]
<input type="text" name="term" maxlength="25" required id="id_term">

</div>

```

I haven’t fiddled with any of the templates no, I’ve also just done a pip force reinstall for Django just in case I’d done anything accidental to get them back to the commit and there’s no change.

Ian

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 29, 2024, 9:01pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/6 "2024-03-29T21:01:41Z")

</div>

> [@ian-atkinson](#):
>
> For testing with the apache I had it write the same output to /tmp (not sure how else I’d see it),

Side note: If you’re using mod\_wsgi, I _thought_ there was an option to direct print output to the Apache error log file. (But it’s been at least 10 years since I’ve worked seriously with it.)

> [@ian-atkinson](#):
>
> Yes I’ve tried using the various options (div, table, p, ul) is doesn’t seem to make a difference they just appear within the tags.

That’s helpful to know, because it almost certainly verifies that it’s not a template issue. (Each one uses a different template.)

What’s interesting is that I see two sets of brackets for the `as_p`

Actually, at this point, I’d need to agree with the other advice you’ve found. I’d try installing and running this with Python 3.11. It’s quite possible that there’s some incongruity between mod\_wsgi and Python 3.12. (What version of mod\_wsgi are you using?)

---

<div class="post-metadata">

**Author:** ![ian-atkinson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ian-atkinson/32/20241_2.png) [@ian-atkinson](https://forum.djangoproject.com/u/ian-atkinson)\
**Post date:** [March 29, 2024, 10:49pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/7 "2024-03-29T22:49:09Z")

</div>

looks like the mod\_wsgi is 5.0.0 I think

Is mod\_wsgi not the recommended way to get these django sites up and running? For a long number of years I worked with perl+apache and then php+apache so went into this looking at python+apache as a natural progression but it doesn’t seem to work as nicely with it in general, I guess as it’s not primarily seen as a web type language,

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 30, 2024, 12:42am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/8 "2024-03-30T00:42:48Z")

</div>

> [@ian-atkinson](#):
>
> Is mod\_wsgi not the recommended way to get these django sites up and running?

That’s a question of who you ask. (It is one of the featured configurations in the docs.)  
I’m not a fan, but that’s me. I’m a huge _non_-fan of mod\_wsgi, it’s too limiting for what I need to support. If I had to use Apache again, I’d use it as a proxy in front of `uwsgi` in a manner similar to how I’d do it with nginx.

---

<div class="post-metadata">

**Author:** ![ian-atkinson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ian-atkinson/32/20241_2.png) [@ian-atkinson](https://forum.djangoproject.com/u/ian-atkinson)\
**Post date:** [April 27, 2024, 10:56am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/9 "2024-04-27T10:56:06Z")

</div>

Just wanted to follow up on this (in case anyone arrives from Google) to say that I’ve switched over to nginx+uwsgi for my projects and this bug has gone away so must definitely be something to do with the mod\_wsgi bit of Apache as expected.

Also probably should have just done it this way in the first place 🙂

---

<div class="post-metadata">

**Author:** ![KarstenSchulz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/karstenschulz/32/16700_2.png) [@KarstenSchulz](https://forum.djangoproject.com/u/KarstenSchulz)\
**Post date:** [May 7, 2024, 5:09pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/10 "2024-05-07T17:09:30Z")

</div>

For the record, I am experiencing the same error. When forms are rendered with `form.as_p` or similar, the square brackets appear in front of the input fields (see screen shot of Django admin login). I haven’t found a solution yet (except to avoid the symptoms by building my forms in the template itself, which is not that hard).  
Versions: Apache 2.4.59, mod\_wsgi 5.0.0, Python 3.12.3 and Django 5.0.5  
If I find out anything about the cause, I will report back here.  
 ![Screenshot 2024-05-07 at 18.57.38](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/e/2eb6e16de37fc860132a31c7ab0efd391648fe92.png)

---

<div class="post-metadata">

**Author:** ![jrthorne](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jrthorne/32/21771_2.png) [@jrthorne](https://forum.djangoproject.com/u/jrthorne)\
**Post date:** [June 7, 2024, 5:47am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/12 "2024-06-07T05:47:21Z")

</div>

It seems to be the form errors are being converted from array to string

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/4/a/4a0e0f5f5c66e67dc7a5edd497634a54243dc9b6.jpeg)  
Server version: Apache/2.4.58 (Ubuntu)  
Ubuntu 24.04  
Python 3.12.3  
Django==4.2

```auto
<section class="modal-container login-modal-container">
        <button class="close-dialog">
          <img src="{% static 'img/close-activity-button-bg.png' %}" alt="Close dialog"/>
        </button>
        <h2>
          Welcome to Safety Town!
        </h2>
		<div class="form-box login">
			<div class="form-header">
        I have an account already.
      </div>
			<form method="post" class="login-form">
        {% if patron_login_form.non_field_errors %}
          <ul class="errorlist">
          {% for error in patron_login_form.non_field_errors %}
            <li>{{ error|escape}}</li>
          {% endfor %}
          </ul>
        {% endif %}
				{% csrf_token %}
        <p>
        {{ patron_login_form.email.errors }}
        <label for="id_email">My email address is</label>
        {{ patron_login_form.email }}
        </p>
				<input type="hidden" name="form_id" value="login">
				<input type="submit" value="Log in" class="pulse-me">
			</form>
		</div>
		<div class="form-box register">
			<div class="form-header">I don't have an account yet. Sign me up!</div>
			<form method="post" class="register-form" id="register-form">
				{% csrf_token %}
                {{ register_form.non_field_errors }}
                <p>
                    {{ register_form.school.errors }}
                    <label for="id_school">Name of your school</label>
                    {{ register_form.school }}
                    <span id="school-help" class="form-help-text show">If you can't find your school in the list, please enter the name in the field above.</span>
                </p>
                <p>
                    {{ register_form.email.errors }}
                    <label for="id_email">Your email address</label>
                    {{ register_form.email }}
                </p>
                <p id="recaptcha-required" style="color:red;display:none">
                    Please check the recaptcha
                </p>
                <p>
                  <div class="g-recaptcha" data-sitekey="{{ re_captcha_site_key }}"></div>
                </p>
				<input type="hidden" name="form_id" value="register">
				<input type="submit" value="Register" class="pulse-me">
			</form>
		</div>
        <div class="clearfix"></div>
    </section>

```

---

<div class="post-metadata">

**Author:** ![MrkGrgsn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrkgrgsn/32/7901_2.png) [@MrkGrgsn](https://forum.djangoproject.com/u/MrkGrgsn)\
**Post date:** [June 20, 2024, 4:30am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/13 "2024-06-20T04:30:37Z")

</div>

After poking around in Django core, I believe this issue is caused by this Python 3.12 bug relating to subinterpreters: [Weird `int. __str__ ` behaviour inside sub-interpreters · Issue #117482 · python/cpython · GitHub](https://github.com/python/cpython/issues/117482) I was able to reproduce the problem using a modified version of the test case.

```auto
import _xxsubinterpreters as interpreters

script = """
import django
from django.conf import settings
from django.forms.utils import ErrorList

settings.configure()
django.setup()

empty = ErrorList([])

print(str(empty))
"""

exec(script)
# Output: ""

interp_id = interpreters.create(isolated=False)
interpreters.run_string(interp_id, script)
# Output: []

```

---

<div class="post-metadata">

**Author:** ![JDM-GBG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jdm-gbg/32/16921_2.png) [@JDM-GBG](https://forum.djangoproject.com/u/JDM-GBG)\
**Post date:** [July 24, 2024, 6:29pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/14 "2024-07-24T18:29:12Z")

</div>

Just chiming in with another case. I had been working on a project under Python 3.10.11, Django 5.0.7, and mod\_wsgi 5.0.0 (Apache Server 2.4.61). Everything on my app’s login page was normal.

Then I re-created the virtual env with Python 3.12.4, keeping all other elements the same. When I pointed Apache to the new environment, the Login page now adds in 3 pairs of square brackets – two pairs of them above the Username entry, and one pair above the Password entry.

If I activate the exact same virtual environment and run the app in the Dev server from a Powershell command line, I do not get the square brackets. So it’s all Apache + mod\_wsgi + Python 3.12.

---

<div class="post-metadata">

**Author:** ![ridafatimakhan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ridafatimakhan/32/23790_2.png) [@ridafatimakhan](https://forum.djangoproject.com/u/ridafatimakhan)\
**Post date:** [September 9, 2024, 8:05am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/15 "2024-09-09T08:05:21Z")

</div>

I am experiencing same bug. Have you found the solution?  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/f/7/f754f2817fa58c57c8ce23372ad5720fbc0335c9.jpeg)

---

<div class="post-metadata">

**Author:** ![MrkGrgsn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrkgrgsn/32/7901_2.png) [@MrkGrgsn](https://forum.djangoproject.com/u/MrkGrgsn)\
**Post date:** [September 9, 2024, 11:28pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/16 "2024-09-09T23:28:50Z")

</div>

Your options are:

1. Wait until the cpython bug referenced in my previous comment has been fixed
2. Use a Python version not affected by the bug, eg, 3.11
3. Use a different WSGI server. See the [Django docs](https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/) for some options besides mod\_wsgi.

---

<div class="post-metadata">

**Author:** ![rajmohanperiyasamy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rajmohanperiyasamy/32/25929_2.png) [@rajmohanperiyasamy](https://forum.djangoproject.com/u/rajmohanperiyasamy)\
**Post date:** [December 24, 2024, 4:00pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/17 "2024-12-24T16:00:05Z")

</div>

I had the same issue with the latest django versions 5 ,4.2.I have downgraded the djagno version and it worked.  
pip3 install Django==3.2

---

<div class="post-metadata">

**Author:** ![KarstenSchulz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/karstenschulz/32/16700_2.png) [@KarstenSchulz](https://forum.djangoproject.com/u/KarstenSchulz)\
**Post date:** [February 3, 2025, 6:43am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/18 "2025-02-03T06:43:03Z")

</div>

Sorry for replying so late. I lost track of this thread.

I have completely switched my deployment from Apache + mod\_wsgi to Gunicorn. No brackets are displayed. Unfortunately, I can’t say what the original cause was or whether it still exists.

---

<div class="post-metadata">

**Author:** ![LePtitJoNadeau](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leptitjonadeau/32/30027_2.png) [@LePtitJoNadeau](https://forum.djangoproject.com/u/LePtitJoNadeau)\
**Post date:** [September 24, 2025, 5:58pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/19 "2025-09-24T17:58:52Z")

</div>

We have exactly the same issue in the production environnement only.

Django: 5.2  
Python: 3.12.3

wsgi: 5.0.0

appache: 2.4.58

The problem look like to be on the method \_\_ **str** \_\_ of **utils.ErrorList** that is not define correctly.  
It’s look like the order of three inherited class do something strange with the definition of the \__str_\_ method.

class ErrorList(UserList, list, RenderableErrorMixin)

Fix:

```auto
def __str__ (self):
    return self.render()

```

Thank you

---

<div class="post-metadata">

**Author:** ![carstenfuchs](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carstenfuchs/32/1139_2.png) [@carstenfuchs](https://forum.djangoproject.com/u/carstenfuchs)\
**Post date:** [September 24, 2025, 6:31pm UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/20 "2025-09-24T18:31:16Z")

</div>

I encountered this bug as well and found @MrkGrgsn’s analysis in [this post](https://forum.djangoproject.com/t/square-brackets-bug/29632/13) to be spot on. A list of possible solutions is provided [here](https://forum.djangoproject.com/t/square-brackets-bug/29632/16).

Since this bug has been fixed in [Python 3.12.5](https://docs.python.org/release/3.12.5/whatsnew/changelog.html#core-and-builtins), upgrading to the latest release in the 3.12 series resolved the issue for me.

---

<div class="post-metadata">

**Author:** ![jrthorne](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jrthorne/32/21771_2.png) [@jrthorne](https://forum.djangoproject.com/u/jrthorne)\
**Post date:** [August 18, 2026, 6:24am UTC](https://forum.djangoproject.com/t/square-brackets-bug/29632/21 "2026-08-18T06:24:29Z")

</div>

This plus another issue with DatePicker caused me to stay with Ubuntu 22.04 for a couple of years.  
I just upgraded to Ubuntu 26.04 which has Apache/2.4.66 (Ubuntu) mod\_wsgi/5.0.2 Python/3.14  
So far so good. I will post again if there are other issues.

I am using Django 6.2
