Display image file from Web2Py in Py4Web

147 views
Skip to first unread message

Erich Meyer

unread,
Sep 15, 2022, 6:22:42 AM9/15/22
to py4web


Hello

I have created an application test in Py4Web using scaffold. From a previous application from Web2Py (https://meyerich.pythonanywhere.com/Mathematik/default/snippet/15), I have saved the first image file image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png'  in the folder test/update. How can I access the image in test/index.html ?

Erich


Jim Steil

unread,
Sep 15, 2022, 8:09:30 AM9/15/22
to py4web
What have you tried?

Do you have a working example of it in web2py?

-Jim

Erich Meyer

unread,
Sep 15, 2022, 8:16:36 AM9/15/22
to py4web
see the link in my question

Jim Steil

unread,
Sep 15, 2022, 8:34:33 AM9/15/22
to py4web
I did - the link fails for me.

-Jim

Erich Meyer

unread,
Sep 15, 2022, 9:28:20 AM9/15/22
to py4web

Alexander Beskopilny

unread,
Sep 15, 2022, 9:35:56 AM9/15/22
to py4web

Jim Steil

unread,
Sep 15, 2022, 9:41:44 AM9/15/22
to py4web
If you take off the /default/snippet/15 then I get the app main page.

-Jim


Erich Meyer

unread,
Sep 15, 2022, 9:42:47 AM9/15/22
to py4web
works, and then click on: Dodekaeder

Erich

Jim Steil

unread,
Sep 15, 2022, 9:45:26 AM9/15/22
to py4web
After going to the home page once, now the link above works.

But, that doesn't show me any code.  What have you tried in py4web?

-Jim

Erich Meyer

unread,
Sep 15, 2022, 9:51:33 AM9/15/22
to py4web
after the last update of my site, it no longer works completely; I can no longer log in; I get:
AttributeError: 'module' object has no attribute 'pbkdf2_hmac'.

Jim Steil

unread,
Sep 15, 2022, 9:59:18 AM9/15/22
to py4web
Just to confirm, it is running web2py, not py4web, correct?

-Jim

Erich Meyer

unread,
Sep 15, 2022, 9:59:58 AM9/15/22
to py4web
completely; I can no longer log in; I get:
AttributeError: 'module' object has no attribute 'pbkdf2_hmac'.

I don't know how to get to the previous version

Erich

Erich Meyer

unread,
Sep 15, 2022, 10:01:30 AM9/15/22
to py4web
jes, it is running web2py on pythonanywhre.com !

Jim Steil

unread,
Sep 15, 2022, 10:08:55 AM9/15/22
to py4web
I searched the web2py forum for pbkdf2_hmac and found this:


There are others too.  I'd start there...

-Jim

Erich Meyer

unread,
Sep 15, 2022, 10:54:14 AM9/15/22
to py4web
Hello again!

In general:
when I create an application test using scaffold, I get the file test/index.html
--------------------------------------------
[[extend 'layout.html']]

<div class="section">
  <div class="vars">
      [[=message]]
  </div>
</div>
-----------------------------------------

What do I have to do to display an image file?

I think I should create a directory test/upload and save the image file in it. What do I have to add in  test/index.htm to display the image?

Greetings Erich

Massimo

unread,
Sep 15, 2022, 11:12:10 AM9/15/22
to py4web
You should be able to do

<img src="/yourapp/download/image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png"/>

or

<img src="[[=URL("download", filename_from_db)]]"/>


Massimo

unread,
Sep 15, 2022, 11:17:57 AM9/15/22
to py4web
Taking a second look. You filename is invalid. We are assuming here that a filename is generated by a py4web/web2py form upload and it is in the database table image field data. In this case the filename should start with "image.data." and not "image_data.". How did you generate that filename? Was it a cut and paste error somehow?

Erich Meyer

unread,
Sep 16, 2022, 2:29:33 AM9/16/22
to py4web
Hi Massimo,
the filename originally starts with "image.image_data."
Erich

Massimo DiPierro

unread,
Sep 16, 2022, 2:36:44 AM9/16/22
to Erich Meyer, py4web
then all good. right?

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/0b02d253-9c8a-4569-92fd-7d6484a39f90n%40googlegroups.com.

Erich Meyer

unread,
Sep 16, 2022, 3:18:04 AM9/16/22
to py4web
Hi Massimo

What I did:
1. I create the app test with the help of scaffold
2. I save the image file in the static folder.
3. I add the index.html file:

-----------------------------
[[extend 'layout.html']]

<div class="section">
  <div class="vars">
      [[=message]]
  </div>
  <img src="image.image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png"/>  
</div>
----------------------------
4. I start the server and call:
127.0.0.1/test
!!!! the image is displayed !!!!
===============================
If I save the image file in the uploads folder and change the index.html to

------------------------------------------
[[extend 'layout.html']]

<div class="section">
  <div class="vars">
      [[=message]]
  </div>
  <img src="uploads/image.image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png"/>  
</div>
-----------------------------------------
then I get in the terminal:

"GET /test/static/uploads/image.image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png HTTP/1.1" - 404 447

only when I copy the uploads folder to the static folder, the image is displayed.

FACIT:
the uploads folder should not be created in scaffold parallel to the static folder.

Greetings Erich

Massimo DiPierro

unread,
Sep 16, 2022, 8:04:48 AM9/16/22
to Erich Meyer, py4web
did you try as i recommended before

  <img src="[[=URL('download','image.image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png')]]"/>

the download action is defined in common.py

Erich Meyer

unread,
Sep 16, 2022, 10:38:19 AM9/16/22
to py4web
Hello Massimo

Your suggestion does not work, only a placeholder is shown. I have tried the two statements side by side:

  <img src="uploads/image.image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png"/>  

  <img src="[[=URL('download','image.image_data.b3e1102f4b87de27.646f64656b61656465725f342e706e67.png')]]"/>

the first shows the picture the second only the placeholder

Greetings Erich

Massimo DiPierro

unread,
Sep 16, 2022, 10:40:59 AM9/16/22
to Erich Meyer, py4web
i will post a complete example later tonight.

or if you post yours, i can help you debug the problem.

Message has been deleted

Massimo

unread,
Sep 17, 2022, 1:24:21 PM9/17/22
to py4web
Here is an example that works for me.

Compare the common.py, maybe yours is corrupted.

cd apps
unzip /path/to/demouploads.zip
start py4web

It will display any uploaded image.

Erich Meyer

unread,
Sep 18, 2022, 2:52:09 AM9/18/22
to py4web
Hello Massimo

Thank you very much for the example! It works for me and it shows me new things. (sessions are not needed)

Greetings Erich
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages