Forums

Styles.css not found

Hey all,

Hoping everyone's staying healthy and safe.

I have just included a new app ('auctions') into my existing Django project, hosted on PythonAnywhere.

The static files are working for every other app in my project, but just not for this new one.

I get a 404 in my error log for my styles.css file for the auctions app!: 2021-01-08 14:15:31,398: Not Found: /static/auctions/styles.css

Here is the access log: <IP> - ellis [08/Jan/2021:14:15:28 +0000] "GET /static/auctions/styles.css HTTP/1.1" 404 179

If I try one of my other apps (e.g. 'fashion'), the styles.css file is found: <IP> - ellis [08/Jan/2021:14:20:05 +0000] "GET /static/fashion/styles.css HTTP/1.1" 200 241

I'm a bit lost. I can confirm that there is a styles.css file included in /static/auctions/, just like there is one included in /static/fashion/ that IS found.

Why is it 404'ing?!

So far I have tried deleting the /static/auctions/ directory and re-calling collectstatic, then reloading the webapp.

Any help would be greatly appreciated. Just confused because the other apps seem the same... but are working :)

Thanks! pic of files

hmm- take a look at your static file mappings on your webapps tab. Double check that your static files are being collected to the correct spot?

Hi Conrad,

Thanks a lot.

Oh damn - I must have messed with that and not changed it back.

I understand now that I had an issue with the static files mapping in the webapps tab, which tells the PA web servers where to look to serve out my static files for me.

I had defined the path for the static file mapping incorrectly. I have changed it to the same value as I had in STATIC_ROOT and it is now working.

Your tutorial on setting up static files in Django is very clear - I should have checked it, but I failed to do so because I was wondering why some apps worked and some didn't. I guess those that did work had been previously 'collectstatic'd to the incorrect path that was entered in the path section of the static files mapping on the webapp tab.

Indeed I have found them in that incorrect directory and deleted them.

Just because the relative file path was the same, didn't mean the absolute one was!

Many thanks again. I appreciate your help.

No problem, glad we were able to help!

The collectstatic command is not working for me in the bashconsole. I got an error saying there is no such file or directory while running the command . Also the CSS file for my django administration page is not working .

See https://help.pythonanywhere.com/pages/DjangoStaticFiles/

I dont know what to do, I have followed the steps and its still not working .

If you're getting a "no such file or directory" error, then check that your Django configuration refers to directories and files that actually exist.