Using bootstrap4 causes a VariableDoesNotExist exception with html5_required missing when displaying a form
See original GitHub issue- Package version: 1.7.2
- Django version: 2.2.4
- Python version: 3.7.4
- Template pack: (Optional) Bootstrap4
Description:
I tried to display a basic update form for my model, when I tried to test it and browsed to the endpoint, a VariableDoesNotExist Exception is thrown. I have to step through/continue the debugger to continue.
Preferably also include:
Error:
#MODEL
class Testmodel(models.Model):
name = models.CharField('name', max_length=50)
text = models.CharField('text', blank=True, max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
# VIEW / FORM
class TestmodelForm(ModelForm):
class Meta:
model = Testmodel
fields = ('name', 'text')
# TODO: need to add selection dropdown and date picker
def test_view(request, *args, **kwargs):
if request.method == "POST":
form = TestmodelForm(request.POST)
if form.is_valid():
profile = form.save(commit=False)
profile.save()
# TODO: add message or redirect ?!
else:
form = TestmodelForm()
return render(request, 'profile.html', {'form': form})
## PROFILE.HTML
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<h2>Profile</h2>
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<button class="btn btn-primary" type="submit">Update</button>
</form>
{% endblock %}
Output:
I think the required field should be marked with a red star and I assume its not and is related to the html5_required being missing?
Where and why is this key/variable missing? is this a bug? Am I doing something wrong? I literally created a naked project to test this issue.
Also at stackexchange with bit more details: https://stackoverflow.com/questions/57454907/crispy-forms-throws-variabledoesnotexist-error-failed-lookup-for-key-html5-requ
EDIT:
I changed in the template how the form is called to:
{% crispy form %}
which doesn’t cause the issue.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top GitHub Comments
This is a VS Code issue. The
VariableDoesNotExist
exception is internal to the template rendering. (It’s not a bug…)A quick search seems to suggest putting
django: false
in the debugger launch config. (Don’t know if that has other consequences…)Can I ask you folks to report this to VS Code, or the authors of whatever extensions you’re using, since it should be addressed there.
it seams like a VS Code issue, need change
"django": false
on launch.json.