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:
└─$ 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
{% block content %}
<form action="{% url 'accounts:search' %}" method="post">
{% csrf_token %}
{{ form.as_table }}
<input type="submit" value="Submit">
</form>
{% endblock %}
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})