My website was doing everything well and showing all the CSS until I ran collectstatic
on it. Now everything is how it would look if CSS didn't exist. Is there any solution to this? Or is there some way I can delete the collectstatic
to get back the previous thing?
I followed this tutorial to host this website: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
Here's my settings.py
(only the last bit where I set the static and the media stuff):
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_DIRS = []
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
LOGIN_URL = '/main/user_login/'
Okay, so as you mentioned it stopped working after you ran collectstatic command. collectstatic command makes Django looks for all static files in your apps and collects them in a single directory which is STATIC_ROOT. (In production it needs a single directory for all the static files)
Put the directories containing your static files into the STATICFILES_DIRS.
You also have to include your static urls in your urls.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [your paths go here]
urlpatterns += staticfiles_urlpatterns()
After including your static directories into the STATICFILES_DIRS array and including the static urls in your urls.py, use the command collectstatic and then it should work.