+5

How to use external CSS/JS in Django

I've got a .html based template. So how do i link this with my external css/js ? I've tried this method {% load static %} <link rel="stylesheet" href="{% static 'my/static/dir.css' %}" > I verified my apps with python manage.py check and it says "no issue found" which means my setup is configured correctly but it won't work?

7/20/2019 7:29:03 AM

Cbr✔[ Most active ]

5 Answers

New Answer

+3

{%load static from staticfiles %} instead of {% load static %}

+11

Check out this <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" /> <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-1.8.3.min.js"></script> Go through the documentation once again https://docs.djangoproject.com/en/dev/howto/static-files/

+6

Roolin Nice suggestion.. Imma try that

+5

PALAK😄😄 That will work for older version of django and they've not been updating their own official documentation idky... Things have really changed in django latest version but the changes are not corrected in their documentation.. {{static_URL}} is a variable in django template for newer version

+3

You could try to add "type='text/css'" after the rel-attribute, but I don't think it's necessary though (worth a try I guess). Also, this might be a stupid question from me, but have you written any styles in your CSS-file that you know for certain will work? If I want to test if CSS is working, I always change the color of something obvious, like the background, just to see if the CSS is working or not. I guess you could also try restarting the server. Good luck!