Pythonanywhere, how to use static files? url?

北慕城南 提交于 2020-01-03 17:45:04

问题


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?


回答1:


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"/>



回答2:


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




回答3:


I've never used PythonAnywhere, but are you sure you've uploaded the files to the proper location on their server? It looks like they've got a custom file handler set up for the users, which you can briefly read up about here

You have a certain amount of storage on our servers in the form of a home folder and a /tmp.

They say they offer certain directories, have you tried pointing to those?



来源:https://stackoverflow.com/questions/19592998/pythonanywhere-how-to-use-static-files-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!