#33995: Key Error 'empty_permitted' when rendering 'formset.empty_form'
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
claypooj21 |
Type: Bug | Status: new
Component: Forms | Version: 4.1
Severity: Normal | Keywords: formset,
Triage Stage: | empty_form, empty_permitted, form
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
== Issue
When explicitly setting {{{ form_kwargs = {'empty_permitted':True} }}} or
{{{ form_kwargs = {'empty_permitted':False} }}}, a KeyError occurs when
rendering a template that uses a formset's {{{empty_form}}}.
== Expected Behavior
{{{empty_permitted}}} is ignored for {{{formset.empty_form}}} since
{{{empty_permitted}}} is irrelevant for {{{empty_form}}}, as
{{{empty_form}}} is not meant to be used to pass data and therefore does
not need to be validated.
== Steps to Reproduce
{{{#!python
# views.py
from django.shortcuts import render
from .models import MyModel
def test_view(request):
context = {}
ff = modelformset_factory(MyModel, fields = ['a_field'])
context['formset'] = ff(
queryset = MyModel.objects.none(),
form_kwargs = {'empty_permitted':True} # or form_kwargs =
{'empty_permitted':False}
)
return render(request, 'my_app/my_model_formset.html', context)
# urls.py
from django.urls import path, include
from .views import test_view
urlpatterns = [
path('test', test_view)
]
# my_model_formset.html
{% extends "my_app/base.html" %}
{% block content %}
<form id="my-form" method="post">
{% csrf_token %}
{{ formset }}
<input type="submit" value="Save">
</form>
{{ formset.empty_form }}
{% endblock %}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33995>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701831b309e27-99509a80-3cea-4b55-b612-1a7e4ec35df1-000000%40eu-central-1.amazonses.com.