Added file upload example
@@ -341,6 +341,20 @@ def actions__submit__post_handler(form, **_):
)
+@example(gettext(("File upload")))
+def form_example_file_upload(request):
+ class FileForm(Form):
+ upload = Field.file()
+
+ class Meta:
+ @staticmethod
+ def actions__submit__post_handler(form, **_):
+ if form.is_valid():
+ print(f"Uploaded {len(form.fields.upload.value)} bytes")
+
+ return FileForm()
+
+
class IndexPage(ExamplesPage):
header = html.h1('Form examples')
description = html.p('Some examples of iommi Forms')
@@ -371,5 +385,6 @@ class Meta:
path('example_10/', form_example_children_that_are_not_fields),
path('example_11/', form_example_children_that_are_not_fields_declarative),
path('example_12/', form_example_nested_forms),
+ path('example_13/', form_example_file_upload),
path('all_fields/', all_field_sorts),
]
