0

PROJECT-BASE.HTML

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 ! website image showing the CSS is not working 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. here's a part of my css Thanks a lot, I hope you all can help me !

10
  • in settings.py set static_url and staticfiles_dir - docs.djangoproject.com/en/2.2/ref/settings/… Commented Nov 26, 2019 at 19:55
  • I already set it but it doesn't seem to work. It still asks me for STATIC_ROOT STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] I tried looking at the documentation but I do not understand anything Commented Nov 26, 2019 at 20:08
  • personal_portfolio is 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. Commented Nov 26, 2019 at 20:12
  • If you are under development - docs.djangoproject.com/en/2.2/howto/static-files/… Commented Nov 26, 2019 at 20:14
  • PERSONAL_PORTFOLIO is my project name. PROJECTS is my app name. I tried putting my personal_portfolio/static/css/navbar.css as rp-portfolio/static/css/navbar.css so it's in the ROOT but it still doesn't work. Commented Nov 26, 2019 at 20:17

2 Answers 2

1

Try using {% load static %} instead of {% load staticfiles %}

Sign up to request clarification or add additional context in comments.

4 Comments

Tried, still doesn't work. I really don't understand why bootstrap works so easily but not css files
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'),
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') ????
I found the same answer ! stackoverflow.com/questions/52403518/… I just needed to add a different dir !
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.