1、在setting.py中新增如下配置,static为静态文件的目录,BASE_DIR为项目根目录

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('\\', '/')),
)

2、在url.py中增加配置

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()

3、在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>

   

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄