-2

I am trying to setup a static url in Django and have my templates use it to link to the css. Here is my code. Why is it not working? Also, what is the best practice for setting this up? Thanks.

# settings

import os

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) 
STATIC_ROOT = os.path.join(PROJECT_PATH, 'static')
STATIC_URL = '/static/'

STATICFILES_DIRS = (

)

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles',
    )


# urls

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

# ... the rest of my URLconfs here ...

urlpatterns += staticfiles_urlpatterns()


# html template

<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css" type="text/css">

# file structure
-project
--project
---settings
---static
----css
-----style.css
user1330225
  • 177
  • 1
  • 2
  • 8

1 Answers1

1

Your STATICFILES_DIRS needs to include a list of paths to your static directories for development. The STATIC_ROOT setting is used for collecting static files into a single directory in production to be served by HTTP server such as Nginx or Apache.

Seeing as you have already defined a PROJECT_ROOT you could do this:

# Assuming your settings.py is at the same level as your static directory
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'), ]
krak3n
  • 948
  • 6
  • 13