How to link images (under static/images) from static folder static html

2,909 views
Skip to first unread message

Jon Subscripted

unread,
Jul 22, 2019, 10:02:43 AM7/22/19
to web...@googlegroups.com
Hi everyone,
I'm experiencing some problems trying to display static images in my static html files. Actually I get a 404 error, when I "inspect" what's going wrong.

Some of the HTML files in my project are fully static (stored along with 403.html, 404.html, 500.html & 503.html) and display images stored in static/images folder. So I tried to link them the traditional way. (I assumed the URL builder cannot be used as the HTMLs are not processed by web2py before being served.)

But it is not working. How should I link those images?

I've tried different approaches but neither of them seems to work.

a) relative path <img src="./images/forks_es3.png" /> (relative inside the app)
b) relative path

<img src="myapp/static/images/forks_es2.png" /> (relative inside the web2py site)

c) absolute path <img src="https://www.myweb.com.eus/myapp/static/images/forks_es.png" />

BTW, it may be important to note that I'm using the "routes.py" using the "parameter-based system" using:

BASE  = dict(default_application='myapp')

Thanks, Jon.

Jon Subscripted

unread,
Jul 29, 2019, 4:43:55 AM7/29/19
to web...@googlegroups.com
Hi everyone,
Any suggestions, please? 
It does work for me in locally (127.0.0.0), but not in PythonAnywhere.
Thanks, Jon.

Dave S

unread,
Jul 29, 2019, 4:27:03 PM7/29/19
to web2py-users


On my server, the following works for both links:

<head>
</head>
<body>
<img src="images/my-logo.png">
<img src="/app2/static/images/my-logo.png">
</body>


 My global routes.py sets (using the "simple router" example)

routers = dict(
   
# base router
    BASE
=dict(default_application='appOne',
                     root_static
= ['favicon.ico, 'robots.txt'])


and I used "app2/static/test-ess.html" to load the page.

I also copied the html to appOne (already had the same logo in static images), and "static/test-ess.html" worked there; both copies of the logo were displayed.

If you have a lot of static files, or some of them are large, you may want to see if you can serve them with your front-end.  I have a vague idea that PythonAnywhere uses Nginx, but I don't know if they give you any control of it.

/dps




Jon Subscripted

unread,
Jul 30, 2019, 4:12:10 PM7/30/19
to web...@googlegroups.com
Thanks Dave,
I'll test using the logo (which actually works) as you suggested.
Regards, Jon.

Libre de virus. www.avast.com

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/8f4c309d-afb7-4ba7-83a5-85a98bbe72e0%40googlegroups.com.

Libre de virus. www.avast.com
Reply all
Reply to author
Forward
0 new messages