STATIC_URL Not Working After Django 1.5 Upgrade

2019-03-01 02:35发布

Im probably just tired and dont notice something obvious here but after upgrade to Django 1.5 the path to my static files is broken.

settings.py

from os.path import abspath, basename, dirname, join, normpath

SITE_ROOT = dirname(dirname(abspath(__file__)))

SITE_NAME = basename(SITE_ROOT)

PROJECT_ROOT = dirname(SITE_ROOT)

STATIC_ROOT = normpath(join(SITE_ROOT, 'static', 'site_media'))

STATIC_URL = "/site_media/static/"

STATICFILES_FINDERS = (
    "staticfiles.finders.FileSystemFinder",
    "staticfiles.finders.AppDirectoriesFinder",
    "staticfiles.finders.LegacyAppDirectoriesFinder",
    "compressor.finders.CompressorFinder",

)

index.html

    <link rel="stylesheet" href="{{ STATIC_URL }}css/site_base.css" />

2条回答
贼婆χ
2楼-- · 2019-03-01 02:50

Because in Django 1.5 you have to use {% load staticfiles %}

 <link rel="stylesheet" href="{{STATIC_URL}}css/site_base.css" />
查看更多
神经病院院长
3楼-- · 2019-03-01 03:10
{% load static from staticfiles %}

<link rel="stylesheet" href="{% static 'css/site_base.css' %}" />

Documentation for the new implementation of Django 1.5:

https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#template-tags

查看更多
登录 后发表回答