.Tang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1.需要配置settings

# 静态文件目录
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')

2.页面加载静态文件

{% load static %} 加载静态文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
    <script src="{% static "js/hello_word.js" %}"></script>   加载static目录下的文件 通过/,  最前面也可以加/js/hello_word.js  
    <script src="{% static "hello_word.js" %}"></script>     加载static下的js和css
    <link rel="stylesheet"  href="{% static 'hello_world.css' %}">
</head>
<body>
  <div class="box">这是引入js,css案例<div>
  <img src="{% static 'images/fruit.jpg' alt='' %}"> 引入static/images/fruit.jpg
</body> </html>

 

posted on 2018-05-08 15:45  .Tang  阅读(165)  评论(0编辑  收藏  举报