-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00da577
commit 2704b13
Showing
1 changed file
with
18 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
from justpy import * | ||
|
||
def on_submit(c, msg): | ||
print(len(msg.form_data[0]["files"][0]["file_content"])) | ||
print(len(msg.form_data[1]["files"][0]["file_content"])) | ||
def handle_submit(c, msg): | ||
fl=msg.page.file_list | ||
fl.components.clear() | ||
for fd in msg.form_data: | ||
if "files" in fd: | ||
for f in fd["files"]: | ||
Li(text=f"File uploaded: {f['name']} of {len(f['file_content'])}", a=fl) | ||
|
||
def multi_uploads(): | ||
wp=WebPage() | ||
form=Form(a=wp, submit=on_submit) | ||
Input(type="file", name="f1", a=form) | ||
Input(type="file", name="f2", a=form) | ||
Input(type="submit", value="OK", a=form) | ||
return wp | ||
def p1(): | ||
wp=WebPage() | ||
f=Form(submit=handle_submit, a=wp) | ||
Input(name="f1", type="file", a=f) | ||
Input(name="f2", type="file", a=f) | ||
Input(type="submit", value="OK", a=f) | ||
wp.file_list=Ol(a=wp) | ||
return wp | ||
|
||
|
||
justpy(multi_uploads) | ||
WebPage.tailwind=False | ||
justpy(p1, start_server=(__name__=="__main__")) |
2704b13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone explain this example? It seems there is a form and submit button. Once the submit button is clicked, it will show list items with file names mentioned in the form.
I don't see this as an example for file upload. Also, why are naming the function p1. Call it launcher or endpoint or some such thing. p1 seems arbitary.
2704b13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File upload is done by the two
<input type="file">
. The actual upload process is done by Justpy when the<form>
is submitted. The justpy website already has an example of file upload, but it didn't work when there were two or more file input fields. This example shows that the updated version works fine with multiple file input fields.p1 means page 1. Yes, it is kind of arbitrary as it is not really relevant; only the file input fields are.