#下一步是告诉Django在哪里可以找到静态文件。打开settings.py,拉到文件的底部,在STATIC_URL后面添加以下内容:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
<!--现在我们必须在模板中加载静态文件(Bootstrap CSS文件):-->
<!--只要记住但凡是引用到CSS,JavaScript或图片文件的地方就是要{% load static %}.-->
<!--templates/home.html-->
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Boards</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<h1>Boards</h1>
<table border="1">
<thead>
<tr>
<th>Board</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for board in boards %}
<tr>
<td>{{ board.name }}<br>
                <small style="color: #888">{{ board.description }}</small>
              </td>
<td>0</td>
<td>0</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
<!--现在我们可以编辑模板,以利用Bootstrap CSS:-->
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Boards</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<div class="container">
<ol class="breadcrumb my-4">
<li class="breadcrumb-item active">Boards</li>
</ol>
<table class="table">
<thead class="thead-inverse">
<tr>
<th>Board</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for board in boards %}
  <tr>
  <td>{{ board.name }}
                  <small class="text-muted d-block">{{ board.description }}</small>
                </td>
  <td class="align-middle">0</td>
  <td class="align-middle">0</td>
  <td></td>
  </tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>

Django入门指南-第9章:静态文件设置(完结)的更多相关文章

  1. Django入门指南-第10章:Django Admin 介绍(完结)

    在浏览器中打开该URL:http://127.0.0.1:8000/admin/ 我们可以检查一切是否正常,打开URL http://127.0.0.1:8000 我们首先创建一个管理员帐户: pyt ...

  2. Django入门指南-第8章:第一个测试用例(完结)

    python manage.py test python manage.py test --verbosity=2 # boards/tests.py from django.core.urlreso ...

  3. Django入门指南-第7章:模板引擎设置(完结)

    http://127.0.0.1:8000/ <!--templates/home.html--> <!DOCTYPE html> <html> <head& ...

  4. Django入门指南-第6章:第一个视图函数(完结)

    http://127.0.0.1:8000/ # boards/views.py from django.http import HttpResponse from .models import Bo ...

  5. django 简易博客开发 3 静态文件、from 应用与自定义

    首先还是贴一下源代码地址  https://github.com/goodspeedcheng/sblog 上一篇博客我们介绍了 django 如何在views中使用templates以及一些常用的数 ...

  6. 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何

    基于 Vue.js 之 iView UI 框架非工程化实践记要   像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引 ...

  7. 完整的Django入门指南学习笔记2

    part2: 前沿 在第一节中,我们安装了项目所需要的一切:Python3.6以及在虚拟环境中运行的Django2.0,这部分教程继续在项目上编写代码. 开始写代码前,先讨论下项目的相关背景知识,然后 ...

  8. 完整的Django入门指南学习笔记7 网页自动翻译

    转自[https://simpleisbetterthancomplex.com/series/2017/10/16/a-complete-beginners-guide-to-django-part ...

  9. Django入门与实践 17-26章总结

    Django入门与实践-第17章:保护视图 Django 有一个内置的视图装饰器 来避免它被未登录的用户访问: 现在如果用户没有登录,将被重定向到登录页面: 现在尝试登录,登录成功后,应用程序会跳转到 ...

随机推荐

  1. django celery 定时任务

    可参考上一篇:http://www.cnblogs.com/wumingxiaoyao/p/8515075.html 1. 安装 django-celery-beat pip3 install dja ...

  2. Linux tomcat启动慢, Creation of SecureRandom instance for session ID generation using [SHA1PRNG]took [xx] mil

    启动慢的解决链接:  http://blog.csdn.net/u011627980/article/details/54024974

  3. eclipse 和 javaClass

    eclipse 如果设置为 Build automaticaly 会自动对当前的类进行编译,放在项目下的bin文件夹下. 1. 如果此Class有错,则编译后的Class不能用,里面仅仅写会抛出异常代 ...

  4. 关于frameset与iframe的使用

    <frameset>与<body>标签同级,是不能同时存在的,<frameset>是把当前页面进行分割. frameset.html: <!DOCTYPE h ...

  5. jenkins systemctl启动失败

    centos yum或者rpm安装jenkins后起不来 vi /etc/init.d/jenkins candidates="/usr/local/jdk1.8.0_171/bin/jav ...

  6. update from

    update table1 set table1.column1 =(select table2.column1 from table2  where 关联条件) where exists(selec ...

  7. css:多个div在同一行显示

    使用float:left,也可以使用display : inline-block,可以使多个div在同一行显示. 示例如下: <div class="search_row"& ...

  8. Spring依赖注入:注解注入

    注解注入顾名思义就是通过注解来实现注入, Spring和注入相关的常见注解有Autowired.Resource.Qualifier.Service.Controller.Repository.Com ...

  9. 注册google账号 解决国内手机注册失败的问题

    1. PC端下载夜神安卓模拟器.安装,启动. 2. 在模拟器里的市场应用里下载qq邮箱. 3. 启动邮箱,选择gmail,注册.后续一切顺利. 这是迄今为止,唯一注册顺利的方法.其他方法,手机验证一关 ...

  10. swift UITextfield 添加点击方法 - 简单实现

    1. 真正在任何系统上都有效的方法 1./// 城市选择 private lazy var cityTextfield:UITextField = { let tf = UITextField() t ...