We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Solving Problems with Django Forms

Formale Metadaten

Titel
Solving Problems with Django Forms
Serientitel
Teil
19
Anzahl der Teile
52
Autor
Lizenz
CC-Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben.
Identifikatoren
Herausgeber
Erscheinungsjahr
Sprache

Inhaltliche Metadaten

Fachgebiet
Genre
Abstract
We'll look at a few core problems that we were able to solve with Django forms. Dynamic Field Creation: What if you don't know what fields should be present on a Django form until runtime?. Solutions: Viewing a form's fields as a data structure (convert a field definition to a dictionary) Manipulate self.fields on a form to dynamically add / remove forms from a field. Pitfalls: A fields validated attributes can't be manipulated dynamically because of Validators within the forms API. Dynamic form layouts become difficult to manage, crispyforms does not scale as a solution! Validate a form via an API: How can external validations behave the same as internal errors? Solutions: form.clean() can be used for form wide errors, and form.add_error can be used to integrate those external validation errors into your existing form so that calls like is_valid() still work as expected with your external validations. Adding fields at runtime: How can the user add fields to a form after it has been rendered? Solutions: Javascript can be used for the UI, and if the fields are properly named, the same validations will work as long as the fields are part of the form. Pitfalls: Creating a solution that creates a dynamic field that is validated, but doesn't render can cause issues with your layout solution (crispyforms fails again here)