我的Django版本是1.9
下图是我的目录结构:
dashboard是我的app名
我在settings.py中加入了这2句
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
在html中我是这样写的
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static "dashboard/css/amazeui.min.css" %}"/>
最后运行测试服务器打开网页,出来下图的错误TAT。。
下图是后台的日志
我在网上找了各种办法,都不行,各路大神们这是为什么!!!!
搞定了。。。
在settings.py中:
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'dashboard/static')
在dashboard/urls.py中:
# coding:utf8
from django.conf.urls import url
from django.conf.urls.static import static
from . import views
from django.conf import settings
app_name = 'dashboard'
urlpatterns = [
url(r'^$', views.index, name='index'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
搞定!
我记得好像template可以跟随app放置,但是static还是需要统一collect一下才能用。
https://docs.djangoproject.com/en/1.9/ref/contrib/staticfiles/#django-admin-collectstatic