Replies: 8 comments 5 replies
-
|
Hi Bill. I'm assuming you are on page 310 (or thereabouts). The KeyError is telling you that the Python/Flask code can't find a HTML interface element with the name "file" in the rendered/generated select.html template. Make sure your display_swimmers_files() function (also shown on page 310) is assigning "file" (all lowercase) to the select_id parameter when calling render_template(). Also, check your select.html template matches the HTML code shown on page 296. --Paul. |
Beta Was this translation helpful? Give feedback.
-
|
hi Paul,
thank you for your prompt response.
i followed your suggestions and went through my typing, restart the program
the problem is fixed--that is i got the pull down list of the swimmers and
list of txt files of the swimmers(same as shown on p.305).
but i got a new problem, when i select the txt file and enter(/showfiles) i
got an error
message again. i updated function produce_bar_chart as on p.307
File "c:\Users\oak\Desktop\learning\webapp\app.py", line 59, in
show_bar_chart
location = swimclub.produce_bar_chart(file_id, "templates/")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\oak\Desktop\learning\webapp\swimclub.py", line 83, in
produce_bar_chart
with open(save_to, "w") as sf:
^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory:
'templates/Ali-12-100m-Back.html'
could you help, thank you in advance
bill
…On Tue, Jan 9, 2024 at 2:40 AM Paul Barry ***@***.***> wrote:
Hi Bill.
I'm assuming you are on page 310 (or thereabouts). The KeyError is telling
you that the Python/Flask code can't find a HTML interface element with the
name "file" in the rendered/generated select.html template. Make sure your
display_swimmers_files() function (also shown on page 310) is assigning
"file" (all lowercase) to the select_id parameter when calling
render_template(). Also, check your select.html template matches the HTML
code shown on page 296.
--Paul.
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASYF52S2CJARLZBPLOLUKZLYNUNABAVCNFSM6AAAAABBSQBUOCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DANRUGA2TG>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
hi paul,
i am using windows 10, with VS code. the template folder you mentioned, i
had "templates" with lower case of "t".
in the mean time i tried the book resources file chap6 got this errors
File
"c:\Users\oak\Downloads\headFirst_python3rdResource\chapter06\webapp\app.py",
line 59, in show_bar_chart
location = swimclub.produce_bar_chart(file_id, "templates/")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"c:\Users\oak\Downloads\headFirst_python3rdResource\chapter06\webapp\swimclub.py",
line 43, in produce_bar_chart
swimmer, age, distance, stroke, times, average, converts =
read_swim_data(fn)
^^^^^^^^^^^^^^^^^^
File
"c:\Users\oak\Downloads\headFirst_python3rdResource\chapter06\webapp\swimclub.py",
line 15, in read_swim_data
with open(FOLDER + filename) as file:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory:
'swimdata/Abi-10-100m-Back.txt'
gger.js HTTP/1.1" 304 -
thank you
bill
…On Thu, Jan 11, 2024 at 1:45 PM Paul Barry ***@***.***> wrote:
Hi Bill.
Sorry for delay in replying (I've been swamped at work this week). I'm not
sure which platform you are on, but if you are running Windows, a common
"gotcha" is that some programmers create a folder called "Templates" (with
an uppercase "T") whereas Flask/Jinja2 expects everything to be lowercase,
i.e., "templates". For some reason, Windows can play fast'n'loose with
case, whereas macOS and Linux are more fussy.
If this is not the case with you, let me know.
--Paul.
—
Reply to this email directly, view it on GitHub
<#3 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASYF52U6ZY65VQBT2Z5YWLLYOBMPNAVCNFSM6AAAAABBSQBUOCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DCMBRGEZTG>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
hi paul,
yes i have the 'swimdata' folder which has 61 files in the 'webapp'
folder.in the 'webapp 'folder i had
static, swimdata. templates folders plus app.py,
swimclub.py, hfpy_utils.py, WebappSupport.ipynb,
whoami.py files.
my problem is refer to p.311 i got swimmers list, swimmers file list
but i cannot get the swimmers chart---that where the errors pop up.
thank you
bill
…On Fri, Jan 12, 2024 at 2:03 AM Paul Barry ***@***.***> wrote:
Hi Bill.
Forgive me if this is a very silly question... but does the "swimdata"
folder exist in your "webapp" and does it contain the files from
swimdata.zip (first introduced in Chapter 2 (and available for download
from the chapter02 folder on GitHUB). In the folder which contains your web
application, you should have (at least) the "app.py" file, a folder called
"templates", and another called "swimdata". See the bottom of page 263 for
an example of what your folder should contain.
--Paul.
—
Reply to this email directly, view it on GitHub
<#3 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASYF52XR4XWRHC3R4QGFJL3YOEC7LAVCNFSM6AAAAABBSQBUOCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DCMBYGIZTQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Hi Bill. When you get a moment, please zip up your webapp folder and attach it to your response. I'll then download your code, take a look, and see if I can work out what the issue is. --Paul. |
Beta Was this translation helpful? Give feedback.
-
|
hi paul,
in the process of send you the zip file, i rerun the app.py to make sure it
still has the problem,
but strangely this time it worked, the problem went away, i have no idea
what happened.
since the problem went away, i continued further to chap 7 and deployed
the code to pythonanywhere
and succeeded. here is the link Welcome to the Swimclub
(glrnoak.pythonanywhere.com) <https://glrnoak.pythonanywhere.com/>
i want to thank you for your help,
i want to mention it to your that your book(head first python 3rd ed) is
very user friendly
bill
…On Sat, Jan 13, 2024 at 3:33 AM Paul Barry ***@***.***> wrote:
Hi Bill.
When you get a moment, please zip up your webapp folder and attach it to
your response. I'll then download your code, take a look, and see if I can
work out what the issue is.
--Paul.
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASYF52RJNUDYUBNWNQM7PATYOJWJPAVCNFSM6AAAAABBSQBUOCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DCMJXGQYTE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Hi Bill. The "debug" setting (introduced in pg 276) won't kick in until you restart your Flask app. If you forget to apply this change, any code changes to your webapp aren't activated until you next restart your app. This might explain why your code wasn't working first time around, then "magically" started to behave. Either way, the main thing is that it works now. ;-) I'm glad you are back up and running... and deployed to the Cloud! Cool. Thanks so much for your kind words, and all the best with the rest of my book. If you get stuck again, you know where to find me. :-) Regards. --Paul. |
Beta Was this translation helpful? Give feedback.
-
|
I had problems very similar to what oakmill described. I too ran the code directly from the zip files and got results similar to what oakmill described. All started working correctly for me when I opened a new window in VS and loaded and ran my project files. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
got stuck at chap6 between /swimmers and /showfiles
got pull down list on /swimmers but no pull down list on /showfiles
terminal window shows
in show_bar_chart file_id = request.form["file"]
The browser (or proxy) sent a request that this server could not understand. KeyError: 'file'
any suggestions thanks
bill
Beta Was this translation helpful? Give feedback.
All reactions