Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pythonanywhere, how to use static files? url?

I am completely new to Pythonanywhere, I cant figure out why static files are not loading... Here is the path where I stored css and images stuff, i.e. static/images/wikiLang.png etc

/static/admin/  /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media    
/static/        /home/saadfast/WikiWorld/static  
/media/         /home/saadfast/WikiWorld/media

where as in the client side how should I use the URL?

what i have done in the search.html:

<div id="TopheaderImg">
  <img src="/home/saadfast/WikiWorld/static/images/wikiLogo.png" width="100px" style="float:middle"/>
  <br />
  <img src="/home/saadfast/WikiWorld/images/wikipediaLang.png" width="100px" style="float:middle"/>
</div>

why the image is not loading? what should the path or URL?

like image 801
Saad Abdullah Avatar asked Dec 25 '22 18:12

Saad Abdullah


2 Answers

PythonAnywhere dev here: I think the problem is in the paths you're using in your HTML. The mapping

/static/        /home/saadfast/WikiWorld/static  

Means that URLs with /static/ at the start will be looked for in the directory /home/saadfast/WikiWorld/static. So that means that where you have

<img src="/home/saadfast/WikiWorld/static/images/wikiLogo.png" width="100px" style="float:middle"/>

You should probably have

<img src="/static/images/wikiLogo.png" width="100px" style="float:middle"/>
like image 111
Giles Thomas Avatar answered Dec 28 '22 09:12

Giles Thomas


There is now a PythonAnywhere wiki page about static files under Django

like image 43
hwjp Avatar answered Dec 28 '22 10:12

hwjp