Search code examples
pythondjangostaticdjango-staticfilesdjango-1.8

STATIC_ROOT setup in Django 1.8


I was tried n I can't set-up as per official documents... I am attaching IMG here, pls give me suggestions, Where is the problem.enter image description here

Or, give me simple steps for it with dictionary tree structure.

Thank you.

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

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


STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    # '/var/www/static/',
)

Solution

  • STATIC_ROOT = 'os.path.join(BASE_DIR, 'static_root', 'static') can't work.

    Try this :

    # define your base directory
    # It will be `absolute/path/to/demo3`
    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    STATIC_URL = '/static/'
    # define where your static files will be collected
    # It will be `absolute/path/to/demo3/static`
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    # keep it empty for the moment
    STATICFILES_DIRS = (
    )
    

    You have to understand STATICFILES_DIRS role :

    Your project will probably also have static assets that aren’t tied to a particular app. In addition to using a static/ directory inside your apps, you can define a list of directories (STATICFILES_DIRS) in your settings file where Django will also look for static files.

    I recommend you to read carefully Django docs : Managing static files