STATIC_URL Not Working After Django 1.5 Upgrade

寵の児 提交于 2019-12-04 05:14:53

问题


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" />

回答1:


{% 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




回答2:


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

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


来源:https://stackoverflow.com/questions/15184245/static-url-not-working-after-django-1-5-upgrade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!