Forums

cannot access image,css,etc

im using web.py, structure below:
/home/mopodo/website/kick.py -> get wsgi function and pass to /var/www/wsgi.py (OK)
/home/mopodo/website/static/images/a.png
/home/mopodo/website/templates/index.html
<img src="../static/images/a.png"> -> this image not show in page the same issue happen with css

i wonder what is the base directory for domain mopodo.pythonanywhere.com?
and why the elements cannot accessed?

Hi mopodo,

We are very close to providing out of the box static files for each web application. However at the moment you can serve static files out of /var/www/static.

It's an undocumented feature because it is a bit of a stopgap until we finish some other work. :-)

So if you create a folder called images in /var/www/static and put a.png inside it then mopodo.pythonanywhere.com/images/a.png would work as you expect it to.

you mean put the files like this:
/var/www/static/images/a.png
/var/www/static/bootstrap/css/a.css

and in html: <img href="static/images/a.png">
<link ref="static/bootstrap/css/a.css ...>

that works?

Files: yes.

Links: just remove the "static" - for example: /images/a.png.

finally it works...thanks buddy
hope static files be put into project directory soon :>

It's definitely a priority for us! Soon each web application will have it's own static files location.

another issue, im using web.py and collect all html in 'template' folder
should i also put template in /var/www/ ?

No, they should stay with the code. One possible complexity is that the directory in which your web app runs is not fixed, so you'll need to give web.py a full path when you specify the template directory; something like this:

render = web.template.render('/home/mopodo/website/templates/')