css not loading

Hello, my css is not loading, it is located in a "static" folder inside my app folder, and in the TEMPLATE_DIRS I put "templates" in which I have the html pages calling that css, in my pc version of the project it worked but on python anywhere I don't know why it is not working anymore. thank yo

Which folder contains the HTML file(s)? Which folder contains the CSS file(s)? What is the HTML line where you refer to the CSS file? i.e. the line with something like "<link rel="stylesheet" href=".

On your own PC static files will be served by the django dev server. In a production setting like PythonAnywhere, you need to

  • set the STATIC_ROOT in your, to, eg, /home/yourusername/myproject/static
  • run collectstatic which will collect static files from your app folders and put them in there
  • set up a static files mapping on the web tab, from /static/ to /home/yourusername/myproject/static

Bonus points for setting up STATIC_URL and using the Django {% static %} template tag, but that's optional.

More info in the Django docs

thank you :D

hi how do I undo collect static?


I dont think there is a way. (If you want to take stuff out of static, you could just manually delete it)


I had added a new css file and it did not load. I followed the steps mentioned above. Set Static Root, run collect static etc. When I did that, none of the css was loaded.

It was my mistake. I had changed STATIC_URL. Now put it back to /static/. The old css files loaded and website displayed. But the new one I added today isn't still rendering. Any idea?

Have you tried reloading the webapp?

Yes, I have pressed the reload button at least a dozen times.

Lets walk through two items of your error log to help you debug:

2015-02-11 10:40:05 Not Found: /static/css/font.css
2015-02-11 10:40:05 Not Found: /static/js/jquery-2.0.3.min.js
  1. Let's look at the second one first. In your static files settings for your webapp, you have set the url /static/ to serve files/folders from /home/amritha/costtool/costool/static/.

    However, there is no jquery-2.0.3 file in your folder /home/amritha/costtool/costool/static/js/, so that's why there is an error when you send out a web request for the url /static/js/jquery-2.0.3.min.js.

  2. Now lets take a look at the first problem. My advice here is basically delete all the other two static file settings, namely:

    /css/ --> /home/amritha/costtool/costtool/static/css/
    /static/ --> /home/amritha/.virtualenvs/costtool/lib/python2.7/site-packages/django/contrib/admin/static

    The first setting implies that you want to get served font.css when you send a web request to the url /css/font.css, and not the url /static/css/font.css. It makes more sense to do that latter, and this is already included when you set /static/ in the first part, so your /css/ setting is extraneous.

    There is a similar problem with your admin stuff- it should be, if anything, /static/admin/, but again, you don't actually need it after you have run collectstatic once.

So you may have noticed that I implied just now that setting /static/ is smart enough to serve the subfoler /static/css/- so why hasn't it served it already in this case?

This is because you have two paths set to the /static/ url, and they are clashing.

An interesting hacky feature about PythonAnywhere is that the two paths would actually merge to both serve /static/- ie. a request to /static/file_1/ would try to get the file from path_1/file_1 or path_2/file_1. However, note that if both paths had file_1, the path higher up in your settings would dominate/overwrite. Here, your admin static url is higher up than your actual correct static url, and since it also has a css folder, that css folder is overriding your intended css folder.

I wrote a quick guide to "Django admin CSS not loading!" which points at our more general Guide to using static files with Django on PythonAnywhere

I deleted the two static file settings given below and ran collect static again.

/css/ --> /home/amritha/costtool/costtool/static/css/ /static/ --> /home/amritha/.virtualenvs/costtool/lib/python2.7/site-packages/django/contrib/admin/static

I still get the Not Found error for font.css. jquery-2.0.3.min.js is not there in js folder so that is a valid error but font.css exists.

2015-02-12 08:52:22,989 :Not Found: /static/css/font.css 2015-02-12 08:52:22,990 :Not Found: /static/js/jquery-2.0.3.min.js



you misspelt costtool...

Oh no! Thank you. It is working now.

It is most likely cached, so to force re-loading on your browser hit CTRL+F5