Django 添加本地bootstrap静态文件配置
2015-05-03 16:30
399 查看
首先在工程下新建static文件夹,进入文件夹,新建js,css,fonts等文件,并将bootstrap等静态文件放入相应的位置。
然后在setting中设置:
将静态文件夹static目录加入STATICFILES_DIRS,确保在app中’django.contrib.staticfiles’已经添加。
然后添加文件路径
此时,在html模版中会根据路径寻找相应的文件。
然后在工程下的url中添加urlpattern
设置完后,就可以在模版文件中调用bootstrap了,调用方法如下
然后在setting中设置:
# Additional locations of static files
STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. os.path.join(os.path.dirname(__file__), '../static'), )
将静态文件夹static目录加入STATICFILES_DIRS,确保在app中’django.contrib.staticfiles’已经添加。
然后添加文件路径
STATIC_PATH = ( os.path.join(os.path.dirname(__file__), '../static/').replace('\\','/'), )
此时,在html模版中会根据路径寻找相应的文件。
然后在工程下的url中添加urlpattern
from mysite1 import settings (r'^static/(?P<path>.*)$', 'django.views.static.serve'{'document_root':settings.STATIC_PATH})
设置完后,就可以在模版文件中调用bootstrap了,调用方法如下
<link href="/static/css/bootstrap.css" rel="stylesheet"> <script src="/static/bootstrap/js/jquery.js"></script> <script src="/static/js/bootstrap.min.js"></script>
相关文章推荐
- Django——静态文件(如bootstrap)的配置
- django 配置静态文件
- 用django-pipeline为静态文件添加hash
- django中url,静态文件,POST请求的配置
- django 静态文件配置
- 第三百八十四节,Django+Xadmin打造上线标准的在线教育平台—路由映射与静态文件配置以及会员注册
- Django开发环境静态文件访问配置
- Django静态文件配置
- django静态文件配置
- Django: 配置和静态文件
- Django1.8 关于 静态文件配置
- Django 配置静态文件
- django静态文件配置
- 使用pycharm手动搭建python语言django开发环境(三) 使用django的apps应用 添加应用静态文件
- Python的Django框架完成一个完整的论坛(2.urls.py配置、静态文件)
- Django静态文件配置
- django 1.11中静态文件的配置
- Django静态文件配置备忘录
- django1.4.5配置静态文件(img,css,js)访问