Hi kernie_xvid -- I can probably help you debug if you give me permission to look at the code in your account, but my guess is that what you're trying to do is read from or write to a static file from within a view rather than from a browser -- that is, you have a Django view that wants to load some data from a file, do something to it, and then return the result. Is that correct?
If so, then the problem is almost certainly that the working directory differs between the two environments. When you run your Django app locally, it will run in the directory where you run the runserver
command from. On PythonAnywhere (and in most production hosting environments), the working directory will be different.
A good way to access files from your views is to have something defined in your settings.py
that you can use to determine the location of your Django code, and then to use that as a root when accessing files. So, for example, in settings.py
you would do this:
import os
SETTINGS_DIR = os.path.dirname(__file__)
Then in the view where you're trying to read the file, you'd do this:
drawFreqWordDiagram(wordInfos, os.path.join(settings.SETTINGS_DIR, "rssDjApp/static/topResults.png"))
...you'd also need this at the top of the views.py file:
import os
from django.conf import settings
It's worth mentioning that this is a different thing to Django's built-in "static files" support; the static files support exists to provide a simple way for requests from a browser to (say) http://someone.pythonanywhere.com/static/foo.png
to load the file foo.png
into the browser without having to write special views for every static file in your app. Of course, you might be trying to do that too...