Hello, I've got a project to do and I've been wanting to implement CSS and JS to my Django project WITHOUT using Bootstrap. And as you can see I have personal_portfolio/static/css/navbar.css
But when I load static files and use the tag inside my base.html the page doesn't apply my stylesheet. I do not understand why !
Whereas when I use bootstrap I have no problem !
I've been wanting to use only CSS and JS cause I want to learn those as well and the project I have requires me to do it myself and not use Bootstrap.
Thanks a lot, I hope you all can help me !
2 Answers
Try using
{% load static %}
instead of {% load staticfiles %}
4 Comments
Zekemaz
Tried, still doesn't work. I really don't understand why bootstrap works so easily but not css files
Raphaël Khan
How are you loading bootstrap? If it is using a CDN then your issue comes from your configuration. Make sure you set
STATIC_URL ='/static/' and STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'personal_portfolio/static'),Zekemaz
Hi, STATICFILES_DIRS = ( os.path.join(BASE_DIR, '/static/'), 'personal_portfolio/static/') I used this and it worked but I don't understand what the os.path.join(BASE_DIR does ? I mean by this why don't I have to put os.path.join(BASE_DIR, 'personal_portfolio/static') ????
Zekemaz
I found the same answer ! stackoverflow.com/questions/52403518/… I just needed to add a different dir !
not sure if this will solve your problem but try running
python manage.py collectstatic
from your terminal before running the django server.
1 Comment
Zekemaz
It Tells me this : File "/Users/gabe/Desktop/Gabe/Programming/Django/rp-portfolio/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 44, in path raise ImproperlyConfigured("You're using the staticfiles app " django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. This is only the end of the Traceback error

static_urlandstaticfiles_dir- docs.djangoproject.com/en/2.2/ref/settings/…personal_portfoliois app or project name ?... you have configured your settings as your static files are under root folder, so be sure it should be under your root project only.