[Answer]-Django Static Files – CSS not working

1👍

you must not use MEDIA_ROOT or MEDIA_URL this is for uploaded media not your static content, and you do not need to setup URL patterns as that is only for django 1.2 or ” if you are using some other server for local development”: https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development

you need to have your static files in:
botstore/botstore/static/botstore/css.css

then use:

HOME_ROOT = os.path.dirname(__file__)

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"

STATIC_ROOT = os.path.join(HOME_ROOT, 'staticfiles')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

then in your HTML you can refer to your static files thus:

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

0👍

I think you need a slash at the end of your path, ie '/home/bkcherry/botstore/botstore/static/'

👤hexist

0👍

If you check official documentation

from django.conf import settings

# ... the rest of your URLconf goes here ...

if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),
    )

MEDIA_ROOT should have / on the end (https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-MEDIA_ROOT)

Leave a comment