您的位置:首页 > 编程语言 > Go语言

django设置静态文件路径方法

2012-05-15 06:57 537 查看
折腾了一个晚上,查了好多文章,都没有用。最后拼拼凑凑,总算是可以了。以下总结方法:

vim mysite/settings.py

加入:
HERE = os.path.dirname(os.path.dirname(__file__))
修改:
MEDIA_ROOT = os.path.join( HERE ,'media').replace('\\','/')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(HERE,'static').replace('\\','/')
STATIC_URL = '/static/'

STATICFILES_DIRS = (
os.path.join(HERE,'app名字/static/').replace('\\','/'),
)
推荐的做法是将静态文件保存在app下的static目录中。


vim mysite/urls.py
from django.conf.urls.static import static

urlpatterns += static(settings.MEDIA_URL , document_root = settings.MEDIA_ROOT )
urlpatterns += static(settings.STATIC_URL, document_root = settings.STATIC_ROOT )


然后这样使用:

<link  type="text/css"  rel="stylesheet" href="/static/css/bootstrap.min.css"/>
<link  type="text/css"  rel="stylesheet" href="/static/css/bootstrap-responsive.css"/>


不知道对大家有没有用,可做参考。

本文出自 “YEELONⒼ ” 博客,请务必保留此出处http://yeelone.blog.51cto.com/1476571/863583
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: