Django 中如何使用css 详细解析

来源:互联网 发布:中国有嘻哈 知乎 编辑:程序博客网 时间:2024/05/21 22:51

按照如下的设置来做就可以了,讲的非常清楚:

settings.py:

MEDIA_ROOT = 'C:/Server/Projects/project_name/static/' MEDIA_URL = '/static/' ADMIN_MEDIA_PREFIX = '/media/' 

urls.py:

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

template file:

<link rel="stylesheet" type="text/css" href="/static/css/style.css" /> 

With the file located here:

"C:/Server/Projects/project_name/static/css/style.css" 
 
转自:http://stackoverflow.com/questions/446026/django-how-do-you-serve-media-stylesheets-and-link-to-them-within-templates
原创粉丝点击