Chubak Chubak - 4 months ago 19
Python Question

django 404 when opening static folder

I have created a /static/ folder in my project's root and changed the settings thusly:

STATIC_URL = '/static/'

STATICFILES_DIR = [os.path.join(BASE_DIR, "static")]


But when I open my localhost/static, it produces a 404 error. Why is that?

Answer

For Django 1.3+:

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static")
]

STATIC_ROOT = path.join(TOP_DIR, 'staticfiles')
STATIC_URL = '/static/'

For apache:

Alias /static /var/my/site/static
<Directory /var/my/site/static>
        Require all granted
</Directory>