一、在setting.py中新增以下配置,static爲靜態文件的目錄,BASE_DIR爲項目根目錄javascript
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_DIRS = ( ('images', os.path.join(STATIC_ROOT, 'images').replace('\\', '/')), ('js', os.path.join(STATIC_ROOT, 'js').replace('\\', '/')), ('css', os.path.join(STATIC_ROOT, 'css').replace('\\', '/')), ('fonts', os.path.join(STATIC_ROOT, 'fonts').replace('\\', '/')), )
二、在url.py中增長配置css
from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns += staticfiles_urlpatterns()
三、在html中引入靜態文件html
{% load static %} <script type="text/javascript" src="{%static 'js/jsencrypt.js'%}"></script> <script type="text/javascript" src="{%static 'js/bootstrap.js'%}"></script> <script type="text/javascript" src="{%static 'js/bootstrap.min.js'%}"></script> <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet" type="text/css"> <link href="{% static 'css/bootstrap.css' %}" rel="stylesheet" type="text/css"> <script type="image/gif" src="{%static 'images/loading.gif'%}"></script>