Forums

Do I need to map EVERY SINGLE views in Django to /home/myself/myproject/static ???

I've followed the tutorial to deploy with static files. In settings.py:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = 'static'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

I've collected the static by

collectstatic  --> 353 static files copied to '/home/gustavk/LingL/static'

But when I go to any views, I've got an error log:

For example:

Not Found: /text_list/static/lwt/js/ajax_text_list.js

(where the views text_list got a line: {% static 'lwt/js/ajax_text_list.js %} )

My solution:

Create a mapping in Web tab, in the STATIC FILES section: for example:

   /text_list/static    /home/gustavk/LingL/static

and now it's working when I go on the text_list view.

My question: Do I really need to create a mapping for every single view that I have to get the static files right?

Thanks a lot in advance!

That sounds odd. You shouldn't need to create more than one row on the static files table if you're using collectstatic.

Can I take a look at your files? We can see them from our admin interface, but we always ask for permission first.

Thanks a lot for your reply! Of course you can, it would be very helpful!

Ah, got it! I should have spotted the problem first time around. In your settings.py you have

STATIC_URL = 'static'

What that's doing is it's specifying that the static URL is relative to each package -- that is, for stuff in your text_list Django app, it will use static URLs like /text_list/static/, which is what you're seeing.

If you change settings.py to have this:

STATIC_URL = '/static/'

...then everything will be underneath the /static/ root URL, so you'll only need to specify that on the "Web" page inside PythonAnywhere.

That's so great! Thank you so much for this answer! Pythonanywhere really rocks!

No problem at all, glad to help!