question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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: image

#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: image

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:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
carltongibsoncommented, Apr 16, 2020

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.

1reaction
dehaicommented, Apr 19, 2020

it seams like a VS Code issue, need change "django": false on launch.json.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crispy forms throws VariableDoesNotExist error failed lookup ...
I tried looking for this specific [html5_required] tag/key but haven't found anybody with the same missing key. I removed the custom login form...
Read more >
6 Reasons - HTML5 Required Attribute Validation not Working
1. The Form Tag has “novalidate” Attribute. This is the first and the most common reason that causes the issue. HTML5 required attribute ......
Read more >
HTML5 Form Validation - Showing All Error Messages
Showing all error messages Open in New Window​​ A couple things to note: 1) If a user attempts to submit a form and...
Read more >
Validating Input | Web Accessibility Initiative (WAI) - W3C
If your web browser supports HTML5, it will not allow you to submit the form without entering text into the input field. Instead,...
Read more >
Client-side form validation - Learn web development | MDN
There are two different types of client-side validation that you'll encounter on the web: Built-in form validation uses HTML form validation ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found