Django doesn't load CSS

612 views
Skip to first unread message

Rafał eM

unread,
Feb 11, 2017, 6:06:13 PM2/11/17
to Django users
Guys,

Following tutorial from djangoproject.com I stuck with loading CSS to the site.

Django 1.10

settings.py:
STATIC_URL = '/static/'

base.html:
<link href="{% static 'css/blog.css' %}" rel="stylesheet" type="text/css">

 the path to blog.css in my project is:
blog/static/blog/css/blog.css

it works perfectly fine when running django webserver on my local machine (# python manage.py runserver), however when putting files on the server it doesn't work anymore. By opening source of the site I can see:
<link href="/static/blog/css/blog.css" rel="stylesheet" type="text/css">

I've found out the workaround - hardcoding the css path to:
<link href="static/css/blog.css" rel="stylesheet" type="text/css">
 
It works, but I'd like to do that in "official" way - using the static tags - "{% static 'css/blog.css' %}"

I've tried by changing and/or setting STATIC_URL, STATIC_ROOT, STATICFILES_DIRS and STATICFILES_FINDERS,  but without any success story. Does any of you have any idea on how to get it working?

ludovic coues

unread,
Feb 12, 2017, 6:18:04 AM2/12/17
to django...@googlegroups.com
Have you tried to run manage.py collectstatic ?
The devserver with debug serve static file from each app, but it
doesn't do it without debug.
The idea is that static files should be served directly by your server
or with a CDN and not requiring any CPU time from django.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/eba57537-c217-49ff-b3e5-ff65796bb8d5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

djangoma...@gmail.com

unread,
Feb 13, 2017, 5:06:39 PM2/13/17
to Django users
Wow, mate, you're the hero! Worked like a charm! 
Thank you very much!
Reply all
Reply to author
Forward
0 new messages