1

I got following settings:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static', 'appname'), )

In my templates I got

 <link rel="stylesheet" href"{% static 'appname/css/main.css' %}" />
  1. My static folder includes default Django admin css and js like /static/css and its working fine.

  2. My same static folder includes /static/appname/css/main.css

Still my css is not coming up. My templates are showing up but without css/js. I got all my folders such as 'templates', static', 'static-files' under my project folder.

My default Django static files are showing after "coollectstatic" under static/admin. But I have no idea how to use "STATICFILES_DIRS" in production to show my project template related static files. I am deploying for production. Please advise.

Shazia Nusrat
  • 174
  • 1
  • 10
  • 36

3 Answers3

1

I figured it out that it needed settings in gunicorn from What is the most common way to configure static files in debug and production for Django . The tutorial is not based on gunicorn but the link attached regarding gunicorn worked fine for me. I am thankful as you guys tried to help and stackoverflow just rocks.

Community
  • 1
  • 1
Shazia Nusrat
  • 174
  • 1
  • 10
  • 36
0

collectstatic copies everything below the paths in STATICFILES_DIRS. So since you are putting appname there your css file will end up at "/static/css/main.css". What you want to do is probably change the setting to:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
Tomas Walch
  • 2,245
  • 1
  • 14
  • 17
  • Tried both ways...it collected static as I miss spelled the folder under static/appname. But later on it collected it but domain in production still says after inspecting element that: "Failed to load resources: the server responded with a status of 404 (not found) http://domain.com/static/css/main.css" and same for js files and others. HTML is coming fine though and css for Admin is also working. – Shazia Nusrat Feb 10 '16 at 09:24
  • I am setting up with Gunicorn and Nginx and every time I make changes I restart both services just to make sure that changes take affect. So the problem is in project based templates related css only. Admin css working just fine as my site set to Debug=False. – Shazia Nusrat Feb 10 '16 at 09:27
0

Change your settings like this

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    os.path.join(BASE_DIR, 'static', 'appname'), 
)

Now you can load your static files like this

{% load staticfiles %}
<link rel="stylesheet" href"{% static 'appname/css/main.css' %}" />
Muhammad Hassan
  • 14,086
  • 7
  • 32
  • 54