在django模板中添加jquery

路径

/project_name
    /app_name
        /templates
            /index.html

    /project_name
        setting.py

    /static
        /js
            jquery.js

导入方法

1.在index.html文件中引用jquery.js文件时,在index.html文件head中如下导入:

<script type="text/javascript"  src='../../static/js/jquery.js' charset="UTF-8"></script>

2.在工程目录下的setting.py中添加如下语句

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(__file__), '../static/').replace('\','/'),
)

特别注意

不能放在index.html同级目录下直接导入,会找不到文件
原文地址:https://www.cnblogs.com/maskerk/p/7903058.html